Skip to content

Commit

Permalink
added test case to reproduce HHH-8373
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouzned authored and brmeyer committed Aug 1, 2013
1 parent e8035cc commit a0d0641
Showing 1 changed file with 25 additions and 4 deletions.
Expand Up @@ -32,21 +32,22 @@

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;
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;

/**
* @author Steve Ebersole
*/
public class BasicCriteriaUsageTest extends BaseEntityManagerFunctionalTestCase {

@Override
public Class[] getAnnotatedClasses() {
return new Class[] { Wall.class, Payment.class };
Expand All @@ -59,9 +60,7 @@ public void testParameterCollection() {
CriteriaQuery<Wall> criteria = em.getCriteriaBuilder().createQuery( Wall.class );
Root<Wall> from = criteria.from( Wall.class );
ParameterExpression param = em.getCriteriaBuilder().parameter( String.class );
SingularAttribute<? super Wall,?> colorAttribute = em.getMetamodel()
.entity( Wall.class )
.getDeclaredSingularAttribute( "color" );
SingularAttribute<? super Wall, ?> 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 );
Expand Down Expand Up @@ -105,4 +104,26 @@ public void testDateCompositeCustomType() {
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<Wall> query = cb.createQuery( Wall.class );
Root<Wall> 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();
}
}

0 comments on commit a0d0641

Please sign in to comment.