openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mircea Lazar" <mvla...@gmail.com>
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:
@Entity
class Log{
	protected Timestamp startTime;
}
Query:
<query>
	SELECT al FROM Log al WHERE al.startTime BETWEEN :start AND :end
ORDER BY al.id ASC
</query>
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(QueryImpl.java:270)
	at org.apache.openjpa.persistence.QueryImpl.validateParameters(QueryImpl.java:257)
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
openjpa-1.0.1-r420667

Thanks,
Mircea

Mime
View raw message