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 c6903fcf2f..00fbee7c22 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 @@ -32,6 +32,7 @@ import java.util.List; import javax.persistence.EntityManager; import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.ParameterExpression; import javax.persistence.criteria.Predicate; @@ -39,7 +40,6 @@ import javax.persistence.criteria.Root; import javax.persistence.metamodel.SingularAttribute; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; -import org.hibernate.ejb.criteria.basic.Payment_; import org.hibernate.testing.TestForIssue; import org.junit.Test; @@ -47,6 +47,7 @@ import org.junit.Test; * @author Steve Ebersole */ public class BasicCriteriaUsageTest extends BaseEntityManagerFunctionalTestCase { + @Override public Class[] getAnnotatedClasses() { return new Class[] { Wall.class, Payment.class }; @@ -59,9 +60,7 @@ public class BasicCriteriaUsageTest extends BaseEntityManagerFunctionalTestCase CriteriaQuery criteria = em.getCriteriaBuilder().createQuery( Wall.class ); Root from = criteria.from( Wall.class ); ParameterExpression param = em.getCriteriaBuilder().parameter( String.class ); - SingularAttribute colorAttribute = em.getMetamodel() - .entity( Wall.class ) - .getDeclaredSingularAttribute( "color" ); + SingularAttribute colorAttribute = em.getMetamodel().entity( Wall.class ).getDeclaredSingularAttribute( "color" ); assertNotNull( "metamodel returned null singular attribute", colorAttribute ); Predicate predicate = em.getCriteriaBuilder().equal( from.get( colorAttribute ), param ); criteria.where( predicate ); @@ -105,4 +104,26 @@ public class BasicCriteriaUsageTest extends BaseEntityManagerFunctionalTestCase em.getTransaction().commit(); em.close(); } + + @Test + @TestForIssue(jiraKey = "HHH-8373") + public void testFunctionCriteria() { + Wall wall = new Wall(); + wall.setColor( "yellow" ); + EntityManager em = getOrCreateEntityManager(); + em.getTransaction().begin(); + em.persist( wall ); + + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery query = cb.createQuery( Wall.class ); + Root root = query.from( Wall.class ); + + query.select( root ).where( cb.equal( root.get( "color" ), cb.lower( cb.literal( "YELLOW" ) ) ) ); + + Wall resultItem = em.createQuery( query ).getSingleResult(); + assertNotNull( resultItem ); + + em.getTransaction().commit(); + em.close(); + } }