HHH-5755 - javax.persistence.criteria.Expression.as() is broken
This commit is contained in:
parent
fa6a2f6159
commit
830d4cd2ab
|
@ -39,15 +39,14 @@ import org.hibernate.ejb.metamodel.Product_;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
|
||||||
public class CastTest extends AbstractMetamodelSpecificTest {
|
public class CastTest extends AbstractMetamodelSpecificTest {
|
||||||
|
|
||||||
private static final int QUANTITY = 2;
|
private static final int QUANTITY = 2;
|
||||||
private CriteriaBuilder builder;
|
|
||||||
|
|
||||||
@Override
|
@Test
|
||||||
public void buildEntityManagerFactory() throws Exception {
|
@TestForIssue( jiraKey = "HHH-5755" )
|
||||||
super.buildEntityManagerFactory();
|
public void testCastToString() {
|
||||||
builder = entityManagerFactory().getCriteriaBuilder();
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
Product product = new Product();
|
Product product = new Product();
|
||||||
|
@ -61,18 +60,22 @@ public class CastTest extends AbstractMetamodelSpecificTest {
|
||||||
em.persist( product );
|
em.persist( product );
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.close();
|
em.close();
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
em = getOrCreateEntityManager();
|
||||||
public void testCastToString() {
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
CriteriaBuilder builder = em.getCriteriaBuilder();
|
||||||
CriteriaQuery<Product> criteria = builder.createQuery( Product.class );
|
CriteriaQuery<Product> criteria = builder.createQuery( Product.class );
|
||||||
Root<Product> root = criteria.from( Product.class );
|
Root<Product> root = criteria.from( Product.class );
|
||||||
criteria.where( builder.equal(root.get(Product_.quantity).as(String.class), builder.literal(String.valueOf(QUANTITY))) );
|
criteria.where( builder.equal(root.get(Product_.quantity).as( String.class ), builder.literal(String.valueOf(QUANTITY))) );
|
||||||
List<Product> result = em.createQuery( criteria ).getResultList();
|
List<Product> result = em.createQuery( criteria ).getResultList();
|
||||||
Assert.assertEquals( 1, result.size() );
|
Assert.assertEquals( 1, result.size() );
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.close();
|
em.close();
|
||||||
|
|
||||||
|
em = getOrCreateEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
em.createQuery( "delete Product" ).executeUpdate();
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue