Issue Type: Bug Bug
Affects Versions: 4.3.0.Beta3
Assignee: Unassigned
Attachments: BasicCriteriaUsageTest.java, Date3Type.java, Payment.java, stacktrace.txt
Components: entity-manager
Created: 31/May/13 1:58 PM
Description:

When trying to use a CompositeCustomType around a java.util.Date with Hibernate 4.3.0.Beta3 (lower 4.x versions seem to be affected as well), the following Criteria query fails (trace attached):

CriteriaQuery<Payment> criteria = em.getCriteriaBuilder().createQuery( Payment.class );
Root<Payment> rp = criteria.from( Payment.class );
Predicate predicate = em.getCriteriaBuilder().equal( rp.get( Payment_.date ), new Date() );
criteria.where( predicate );
TypedQuery<Payment> q = em.createQuery( criteria );
List<Payment> payments = q.getResultList();

There is a workaround by substituting the "new Date()" from

equal( rp.get( Payment_.date ), new Date() )

with a ParameterExpression such as :

ParameterExpression<Date> dateParam = cb.parameter(Date.class, "date");

The problem seems to be linked with the extractParameterInfo method from org.hibernate.jpa.internal.QueryImpl and specifically the mightNeedRedefinition method which resets the NamedParameterDescriptor's expected type for date objects :

private boolean mightNeedRedefinition(Class javaType)

{ // for now, only really no for dates/times/timestamps return java.util.Date.class.isAssignableFrom( javaType ); }

You can reproduce this issue by executing the testDateCompositeCustomType attached.

I've developed a fix that I'll submit on github.

Project: Hibernate ORM
Labels: hibernate jpa CompositeCustomType Date
Priority: Minor Minor
Reporter: francois gerodez
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira