openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mircea Lazar" <>
Subject Conversion of Temporal parameters in queries
Date Fri, 04 Jan 2008 12:37:46 GMT
Hi All,

While crosschecking our code against existing JPA providers, I've
found that temporal queries are handled different by OpenJPA.
The entity:
class Log{
	protected Timestamp startTime;
	SELECT al FROM Log al WHERE al.startTime BETWEEN :start AND :end
used as:
query.setParameter("start", start, TemporalType.TIMESTAMP);
query.setParameter("end", end, TemporalType.TIMESTAMP);
where start and end are of type java.util.Date.

When invoked, the query will throw the following exception:
<openjpa-1.0.1-r420667:592145 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: The parameter
"start" is of type "java.util.Date", but the declaration in the query
is for type "java.sql.Timestamp".
	at org.apache.openjpa.persistence.QueryImpl.validateParameter(
	at org.apache.openjpa.persistence.QueryImpl.validateParameters(
The query as is works with both TopLink Essentials and Hibernate.
What would be the correct behaviour: to reject such a query(like
openjpa) or transparently convert java.util.Date to Timestamp for
queries(like the others)?

OpenJPA appears to ignore the temporal indications in setParameter
because QueryImpl is as this:
public OpenJPAQuery setParameter(int position, Date value,
   TemporalType type) {
   return setParameter(position, value);

My stack:
Java 1.6
Glassfish v2


View raw message