diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java index ed97a0fdc6..0e8640fbba 100755 --- a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java @@ -58,6 +58,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.hql.internal.QueryExecutionRequestException; import org.hibernate.internal.SQLQueryImpl; import org.hibernate.internal.AbstractQueryImpl; +import org.hibernate.type.CompositeCustomType; import static javax.persistence.TemporalType.DATE; import static javax.persistence.TemporalType.TIME; @@ -110,7 +111,7 @@ public class QueryImpl extends org.hibernate.ejb.AbstractQueryImpl impleme final NamedParameterDescriptor descriptor = queryImpl.getParameterMetadata().getNamedParameterDescriptor( name ); Class javaType = namedParameterTypeRedefinition.get( name ); - if ( javaType != null && mightNeedRedefinition( javaType ) ) { + if ( javaType != null && mightNeedRedefinition( javaType, descriptor.getExpectedType().getClass() ) ) { descriptor.resetExpectedType( sfi().getTypeResolver().heuristicType( javaType.getName() ) ); @@ -150,9 +151,10 @@ public class QueryImpl extends org.hibernate.ejb.AbstractQueryImpl impleme return (SessionFactoryImplementor) getEntityManager().getFactory().getSessionFactory(); } - private boolean mightNeedRedefinition(Class javaType) { - // for now, only really no for dates/times/timestamps - return java.util.Date.class.isAssignableFrom( javaType ); + private boolean mightNeedRedefinition(Class javaType, Class expectedType) { + // only redefine dates/times/timestamps that are not wrapped in a CompositeCustomType + return java.util.Date.class.isAssignableFrom( javaType ) + && !CompositeCustomType.class.isAssignableFrom( expectedType ); } private static class ParameterImpl implements Parameter { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/BasicCriteriaUsageTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/BasicCriteriaUsageTest.java index 80492a1d2d..c6903fcf2f 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/BasicCriteriaUsageTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/BasicCriteriaUsageTest.java @@ -23,19 +23,25 @@ */ package org.hibernate.ejb.criteria.basic; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; + import javax.persistence.EntityManager; +import javax.persistence.TypedQuery; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.ParameterExpression; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; import javax.persistence.metamodel.SingularAttribute; -import org.junit.Test; - import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import org.hibernate.ejb.criteria.basic.Payment_; +import org.hibernate.testing.TestForIssue; +import org.junit.Test; /** * @author Steve Ebersole @@ -43,7 +49,7 @@ import static org.junit.Assert.assertNotNull; public class BasicCriteriaUsageTest extends BaseEntityManagerFunctionalTestCase { @Override public Class[] getAnnotatedClasses() { - return new Class[] { Wall.class }; + return new Class[] { Wall.class, Payment.class }; } @Test @@ -74,4 +80,29 @@ public class BasicCriteriaUsageTest extends BaseEntityManagerFunctionalTestCase em.getTransaction().commit(); em.close(); } + + @Test + @TestForIssue(jiraKey = "HHH-8283") + public void testDateCompositeCustomType() { + Payment payment = new Payment(); + payment.setAmount( new BigDecimal( 1000 ) ); + payment.setDate( new Date() ); + + EntityManager em = getOrCreateEntityManager(); + em.getTransaction().begin(); + em.persist( payment ); + + CriteriaQuery criteria = em.getCriteriaBuilder().createQuery( Payment.class ); + Root rp = criteria.from( Payment.class ); + Predicate predicate = em.getCriteriaBuilder().equal( rp.get( Payment_.date ), new Date() ); + criteria.where( predicate ); + + TypedQuery q = em.createQuery( criteria ); + List payments = q.getResultList(); + + assertEquals( 1, payments.size() ); + + em.getTransaction().commit(); + em.close(); + } }