Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to do timestamp searches in JPA query language

843830Aug 16 2006 — edited Dec 6 2006
Since the Java Persistence API is part of EJB3, maybe this is the correct forum for this question.

I'm a newbie with JPA. Using it standalone, not as part of an EJB3 app. I have an entity class with a java.util.Date field in it, named 'timestamp' that is annotated as @Temporal(value = TemporalType.TIMESTAMP). This annotation makes the timestamp into a java.sql.Timestamp type, which is what I want, I think, since I need both date and time and the other options produce either java.sql.Date or java.sql.Time, neither of which include both the date and the time.

Question 1: TemporalType.TIMESTAMP is what I want, right?

When I instantiate an entity object of this type I provide a java.util.Date that somehow magically gets turned into a java.sql.Timestamp when it gets persisted. Right?

Question 2: How can I later do a JPA query language (aka EJB3 query language) query against that database using a WHERE clause with a constraint on the time?

For example, I want something like this:
SELECT t FROM tablename t WHERE t.timestamp>something
More explicit question 2: What should the "something" be in that query?

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 3 2007
Added on Aug 16 2006
1 comment
708 views