users@glassfish.java.net

JPA problem with Timestamp

From: <glassfish_at_javadesktop.org>
Date: Thu, 20 Nov 2008 06:13:44 PST

I have problem with timestamp in JPA query.
I wonna select all data from database where difference between two timestamps is more than 2 month.

Database:
ID timestamp1 timestamp2
1 20008-11-19 15:02000 20008-08-19 15:02000
2 20008-11-19 15:02000 20008-11-14 15:02000
......
        @Column(name = "timestamp1", nullable = false)
        @Temporal(TemporalType.TIMESTAMP)
        public Date timestamp1;

        @Column(name = "timestamp2", nullable = false)
        @Temporal(TemporalType.TIMESTAMP)
        public Date timestamp2;
........
sql query works:
select id from table where
MONTH( DATE(timestamp1) - DATE(timestamp2) ) > 3
........
but how I can write in Java?
I't doesnt wrk:
Query query = em.createQuery("SELECT id FROM table WHERE MONTH( DATE(timestamp1) - DATE(timestamp2) ) > 3 ")
[Message sent by forum member 'du27177' (du27177)]

http://forums.java.net/jive/thread.jspa?messageID=317857