[ 
https://issues.apache.org/jira/browse/OPENJPA-497?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12560738#action_12560738
 ] 

Craig Russell commented on OPENJPA-497:
---------------------------------------

This patch doesn't fix the problem but reorganizes the code for a fix.

The method convertTemporalType probably belongs in a utility package, but which 
one? It uses the TemporalType class which is defined in JPA but the 
implementation will depend on the JDBC type package. There doesn't seem to be 
any good place for the utility method. :-(

So, should convertTemporalType be moved to the JPA JDBC project, or should the 
method refer to utility functions in the JPA JDBC project? Or something else?

Index: 
trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
===================================================================
--- 
trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
       (revision 613460)
+++ 
trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
       (working copy)
@@ -416,15 +416,19 @@
     }
 
     public OpenJPAQuery setParameter(int position, Calendar value,
-        TemporalType t) {
-        return setParameter(position, value);
+        TemporalType type) {
+        return setParameter(position, convertTemporalType(value, type));
     }
 
     public OpenJPAQuery setParameter(int position, Date value,
         TemporalType type) {
-        return setParameter(position, value);
+        return setParameter(position, convertTemporalType(value, type));
     }
 
+    protected Object convertTemporalType(Object parameter, TemporalType type) {
+        return parameter;
+    }
+
     public OpenJPAQuery setParameter(int position, Object value) {
         _query.assertOpen();
         _em.assertNotCloseInvoked();



> Incorect handling of temporal parameters in queries
> ---------------------------------------------------
>
>                 Key: OPENJPA-497
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-497
>             Project: OpenJPA
>          Issue Type: Bug
>    Affects Versions: 1.0.1
>         Environment: Java 1.6
> Glassfish v2
> openjpa-1.0.1-r420667
>            Reporter: Mircea Lazar
>            Priority: Minor
>
> The entity:
> For an entity:
> @Entity
> class Log{
>       protected Timestamp startTime;
> }
> given the query
> SELECT al FROM Log al WHERE al.startTime BETWEEN :start AND :end ORDER BY 
> al.id ASC
> If the query is used as:
> query.setParameter("start", start, TemporalType.TIMESTAMP);
> query.setParameter("end", end, TemporalType.TIMESTAMP);
> where start and end are of type java.util.Date, an exception will be thrown:
> 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)
> 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);
> }
> The Date parameter should be converted to Timestamp inside setParameter 
> method.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to