We're updating the issue view to help you get more done. 

JdbcSQLException with CompositeCustomType and java.util.Date

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.

Environment

None

Status

Assignee

Brett Meyer

Reporter

Ouzned Alleykatze

Fix versions

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

4.3.0.Beta3

Priority

Minor