6 - SQM based on JPA type system

- focus on reducing compilation errors
This commit is contained in:
Steve Ebersole 2019-07-12 12:20:33 -05:00 committed by Andrea Boriero
parent 3d5209d105
commit 1713e82d24
68 changed files with 355 additions and 457 deletions

View File

@ -29,8 +29,6 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.hql.internal.ast.tree.JavaConstantNode;
import org.hibernate.internal.util.ConfigHelper; import org.hibernate.internal.util.ConfigHelper;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
@ -349,18 +347,11 @@ public class AttributeConverterTest extends BaseUnitTestCase {
s = sf.openSession(); s = sf.openSession();
s.beginTransaction(); s.beginTransaction();
entity = (EntityWithConvertibleField) s.load( EntityWithConvertibleField.class, entityID ); entity = s.load( EntityWithConvertibleField.class, entityID );
assertEquals( ConvertibleEnum.VALUE, entity.getConvertibleEnum() ); assertEquals( ConvertibleEnum.VALUE, entity.getConvertibleEnum() );
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
JavaConstantNode javaConstantNode = new JavaConstantNode();
javaConstantNode.setExpectedType( type );
javaConstantNode.setSessionFactory( (SessionFactoryImplementor) sf );
javaConstantNode.setText( "org.hibernate.test.converter.AttributeConverterTest$ConvertibleEnum.VALUE" );
final String outcome = javaConstantNode.getRenderText( (SessionFactoryImplementor) sf );
assertEquals( "'VALUE'", outcome );
s = sf.openSession(); s = sf.openSession();
s.beginTransaction(); s.beginTransaction();
s.createQuery( "FROM EntityWithConvertibleField e where e.convertibleEnum = org.hibernate.test.converter.AttributeConverterTest$ConvertibleEnum.VALUE" ) s.createQuery( "FROM EntityWithConvertibleField e where e.convertibleEnum = org.hibernate.test.converter.AttributeConverterTest$ConvertibleEnum.VALUE" )

View File

@ -14,9 +14,9 @@ import javax.persistence.InheritanceType;
import javax.persistence.MappedSuperclass; import javax.persistence.MappedSuperclass;
import org.hibernate.cfg.AnnotationBinder; import org.hibernate.cfg.AnnotationBinder;
import org.hibernate.hql.internal.ast.QuerySyntaxException;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.query.SemanticException;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.logger.LoggerInspectionRule; import org.hibernate.testing.logger.LoggerInspectionRule;
@ -75,7 +75,7 @@ public class MappedSuperclassInheritanceTest extends BaseEntityManagerFunctional
entityManager.createQuery("from Employee").getResultList(); entityManager.createQuery("from Employee").getResultList();
fail(); fail();
} catch (Exception expected) { } catch (Exception expected) {
QuerySyntaxException rootException = (QuerySyntaxException) ExceptionUtil.rootCause(expected); SemanticException rootException = (SemanticException) ExceptionUtil.rootCause( expected);
assertEquals("Employee is not mapped", rootException.getMessage()); assertEquals("Employee is not mapped", rootException.getMessage());
} }
} ); } );

View File

@ -25,13 +25,11 @@ package org.hibernate.test.inheritance.discriminator;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.persistence.AssociationOverride; import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides; import javax.persistence.AssociationOverrides;
import javax.persistence.Basic; import javax.persistence.Basic;
@ -52,14 +50,12 @@ import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OrderColumn; import javax.persistence.OrderColumn;
import org.hibernate.hql.spi.QueryTranslator; import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test; import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
/** /**
* @author Christian Beikov * @author Christian Beikov
@ -116,27 +112,28 @@ public class MultiInheritanceImplicitDowncastTest extends BaseCoreFunctionalTest
} }
private void testMultiJoinAddition(String hql) { private void testMultiJoinAddition(String hql) {
final HQLQueryPlan plan = sessionFactory().getQueryInterpretationCache().getHQLQueryPlan( throw new NotYetImplementedFor6Exception( getClass() );
hql, // final HQLQueryPlan plan = sessionFactory().getQueryInterpretationCache().getHQLQueryPlan(
false, // hql,
Collections.EMPTY_MAP // false,
); // Collections.EMPTY_MAP
assertEquals( 1, plan.getTranslators().length ); // );
final QueryTranslator translator = plan.getTranslators()[0]; // assertEquals( 1, plan.getTranslators().length );
final String generatedSql = translator.getSQLString(); // final QueryTranslator translator = plan.getTranslators()[0];
// final String generatedSql = translator.getSQLString();
int sub1JoinColumnIndex = generatedSql.indexOf( ".base_sub_1" ); //
assertNotEquals( // int sub1JoinColumnIndex = generatedSql.indexOf( ".base_sub_1" );
"Generated SQL doesn't contain a join for 'base' with 'PolymorphicSub1' via 'base_sub_1':\n" + generatedSql, // assertNotEquals(
-1, // "Generated SQL doesn't contain a join for 'base' with 'PolymorphicSub1' via 'base_sub_1':\n" + generatedSql,
sub1JoinColumnIndex // -1,
); // sub1JoinColumnIndex
int sub2JoinColumnIndex = generatedSql.indexOf( ".base_sub_2" ); // );
assertNotEquals( // int sub2JoinColumnIndex = generatedSql.indexOf( ".base_sub_2" );
"Generated SQL doesn't contain a join for 'base' with 'PolymorphicSub2' via 'base_sub_2':\n" + generatedSql, // assertNotEquals(
-1, // "Generated SQL doesn't contain a join for 'base' with 'PolymorphicSub2' via 'base_sub_2':\n" + generatedSql,
sub2JoinColumnIndex // -1,
); // sub2JoinColumnIndex
// );
} }
@MappedSuperclass @MappedSuperclass

View File

@ -6,8 +6,11 @@
*/ */
package org.hibernate.test.inheritance.discriminator.joinedsubclass; package org.hibernate.test.inheritance.discriminator.joinedsubclass;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;
import org.hibernate.resource.transaction.spi.TransactionStatus; import org.hibernate.resource.transaction.spi.TransactionStatus;
import org.junit.Before; import org.junit.Before;
@ -84,9 +87,11 @@ public class JoinedSubclassTest extends BaseCoreFunctionalTestCase {
public void shouldRetrieveSubSubEntityWithCriteria() { public void shouldRetrieveSubSubEntityWithCriteria() {
session = openSession(); session = openSession();
try { try {
SubSubEntity loaded = (SubSubEntity) session.createCriteria( SubSubEntity.class ) final CriteriaBuilder criteriaBuilder = session.getSessionFactory().getCriteriaBuilder();
.add( Restrictions.idEq( subSubEntityId ) ) final CriteriaQuery<SubSubEntity> criteria = criteriaBuilder.createQuery( SubSubEntity.class );
.uniqueResult(); final Root<SubSubEntity> root = criteria.from( SubSubEntity.class );
criteria.where( criteriaBuilder.equal( root.get( SubSubEntity_.id ), subSubEntityId ) );
final SubSubEntity loaded = session.createQuery( criteria ).uniqueResult();
assertNotNull( loaded ); assertNotNull( loaded );
} }
finally { finally {
@ -98,9 +103,12 @@ public class JoinedSubclassTest extends BaseCoreFunctionalTestCase {
public void shouldNotRetrieveSubSubSubEntityWithCriteria() { public void shouldNotRetrieveSubSubSubEntityWithCriteria() {
session = openSession(); session = openSession();
try { try {
SubSubSubEntity loaded = (SubSubSubEntity) session.createCriteria( SubSubSubEntity.class ) final CriteriaBuilder criteriaBuilder = session.getSessionFactory().getCriteriaBuilder();
.add( Restrictions.idEq( subSubEntityId ) ) final CriteriaQuery<SubSubSubEntity> criteria = criteriaBuilder.createQuery( SubSubSubEntity.class );
.uniqueResult(); final Root<SubSubSubEntity> root = criteria.from( SubSubSubEntity.class );
criteria.where( criteriaBuilder.equal( root.get( SubSubSubEntity_.id ), subSubEntityId ) );
final SubSubEntity loaded = session.createQuery( criteria ).uniqueResult();
assertNull( loaded ); assertNull( loaded );
} }
finally { finally {
@ -116,7 +124,7 @@ public class JoinedSubclassTest extends BaseCoreFunctionalTestCase {
try { try {
SubSubEntity loaded = (SubSubEntity) session.createQuery( SubSubEntity loaded = (SubSubEntity) session.createQuery(
"select se from SubSubEntity se where se.id = :id" ) "select se from SubSubEntity se where se.id = :id" )
.setLong( "id", subSubEntityId ) .setParameter( "id", subSubEntityId )
.uniqueResult(); .uniqueResult();
assertNotNull( loaded ); assertNotNull( loaded );
} }
@ -131,7 +139,7 @@ public class JoinedSubclassTest extends BaseCoreFunctionalTestCase {
try { try {
SubSubSubEntity loaded = (SubSubSubEntity) session.createQuery( SubSubSubEntity loaded = (SubSubSubEntity) session.createQuery(
"select se from SubSubSubEntity se where se.id = :id" ) "select se from SubSubSubEntity se where se.id = :id" )
.setLong( "id", subSubEntityId ) .setParameter( "id", subSubEntityId )
.uniqueResult(); .uniqueResult();
assertNull( loaded ); assertNull( loaded );
} }

View File

@ -9,9 +9,8 @@ package org.hibernate.test.naturalid.cid;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.criterion.Restrictions;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test; import org.junit.Test;
@ -72,10 +71,7 @@ public class CompositeIdAndNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
u = ( Account ) s.createCriteria( Account.class ) u = s.bySimpleNaturalId( Account.class ).load( "testAcct" );
.add( Restrictions.naturalId().set( "shortCode", "testAcct" ) )
.setCacheable( true )
.uniqueResult();
assertNotNull( u ); assertNotNull( u );
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();

View File

@ -6,21 +6,19 @@
*/ */
package org.hibernate.test.naturalid.immutable; package org.hibernate.test.naturalid.immutable;
import javax.persistence.PersistenceException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import javax.persistence.PersistenceException;
import org.junit.Test;
import org.hibernate.FetchMode;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.criterion.Restrictions;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.tuple.entity.EntityMetamodel; import org.junit.Test;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -107,9 +105,7 @@ public class ImmutableEntityNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
p = (Parent) s.createCriteria(Parent.class) p = s.createQuery( "from Parent p join fetch p.children where p.name = 'alex'", Parent.class )
.add( Restrictions.eq("name", "alex") )
.setFetchMode("children", FetchMode.JOIN)
.setCacheable( true ) .setCacheable( true )
.uniqueResult(); .uniqueResult();

View File

@ -8,17 +8,15 @@ package org.hibernate.test.naturalid.immutable;
import javax.persistence.PersistenceException; import javax.persistence.PersistenceException;
import org.junit.Test;
import org.hibernate.HibernateException;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.criterion.Restrictions;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
@ -112,10 +110,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
u = ( User ) s.createCriteria( User.class ) u = s.bySimpleNaturalId( User.class ).load( "steve" );
.add( Restrictions.naturalId().set( "userName", "steve" ) )
.setCacheable( true )
.uniqueResult();
assertNotNull( u ); assertNotNull( u );
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
@ -135,17 +130,11 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
u = ( User ) s.createCriteria( User.class ) u = s.bySimpleNaturalId( User.class ).load( "steve" );
.add( Restrictions.naturalId().set( "userName", "steve" ) )
.setCacheable( true )
.uniqueResult();
assertNotNull( u ); assertNotNull( u );
assertEquals( 1, sessionFactory().getStatistics().getNaturalIdQueryExecutionCount() ); //0: incorrect stats since hbm.xml can't enable NaturalId caching assertEquals( 1, sessionFactory().getStatistics().getNaturalIdQueryExecutionCount() ); //0: incorrect stats since hbm.xml can't enable NaturalId caching
assertEquals( 0, sessionFactory().getStatistics().getNaturalIdCacheHitCount() ); //1: no stats since hbm.xml can't enable NaturalId caching assertEquals( 0, sessionFactory().getStatistics().getNaturalIdCacheHitCount() ); //1: no stats since hbm.xml can't enable NaturalId caching
u = ( User ) s.createCriteria( User.class ) u = s.bySimpleNaturalId( User.class ).load( "steve" );
.add( Restrictions.naturalId().set( "userName", "steve" ) )
.setCacheable( true )
.uniqueResult();
assertNotNull( u ); assertNotNull( u );
assertEquals( 1, sessionFactory().getStatistics().getNaturalIdQueryExecutionCount() ); //0: incorrect stats since hbm.xml can't enable NaturalId caching assertEquals( 1, sessionFactory().getStatistics().getNaturalIdQueryExecutionCount() ); //0: incorrect stats since hbm.xml can't enable NaturalId caching
assertEquals( 0, sessionFactory().getStatistics().getNaturalIdCacheHitCount() ); //2: no stats since hbm.xml can't enable NaturalId caching assertEquals( 0, sessionFactory().getStatistics().getNaturalIdCacheHitCount() ); //2: no stats since hbm.xml can't enable NaturalId caching
@ -172,10 +161,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
u = ( User ) s.createCriteria( User.class ) u = s.bySimpleNaturalId( User.class ).load( "steve" );
.add( Restrictions.naturalId().set( "userName", "steve" ) )
.setCacheable( true )
.uniqueResult();
assertNotNull( u ); assertNotNull( u );
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
@ -188,11 +174,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
u = ( User ) s.createCriteria( User.class ) u = s.bySimpleNaturalId( User.class ).load( "steve" );
.add( Restrictions.naturalId().set( "userName", "steve" ) )
.setCacheable( true )
.uniqueResult();
assertNotNull( u );
assertEquals( 1, sessionFactory().getStatistics().getNaturalIdQueryExecutionCount() ); //0: incorrect stats since hbm.xml can't enable NaturalId caching assertEquals( 1, sessionFactory().getStatistics().getNaturalIdQueryExecutionCount() ); //0: incorrect stats since hbm.xml can't enable NaturalId caching
assertEquals( 0, sessionFactory().getStatistics().getNaturalIdCacheHitCount() ); //1: no stats since hbm.xml can't enable NaturalId caching assertEquals( 0, sessionFactory().getStatistics().getNaturalIdCacheHitCount() ); //1: no stats since hbm.xml can't enable NaturalId caching
@ -203,10 +185,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
u = ( User ) s.createCriteria( User.class ) u = s.bySimpleNaturalId( User.class ).load( "steve" );
.add( Restrictions.naturalId().set( "userName", "steve" ) )
.setCacheable( true )
.uniqueResult();
assertNull( u ); assertNull( u );
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
@ -227,10 +206,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
u = ( User ) s.createCriteria( User.class ) u = s.bySimpleNaturalId( User.class ).load( "steve" );
.add( Restrictions.naturalId().set( "userName", "steve" ) )
.setCacheable( true )
.uniqueResult();
assertNotNull( u ); assertNotNull( u );
assertEquals( 1, sessionFactory().getStatistics().getNaturalIdQueryExecutionCount() ); assertEquals( 1, sessionFactory().getStatistics().getNaturalIdQueryExecutionCount() );
@ -241,10 +217,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s.getTransaction().commit(); s.getTransaction().commit();
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
u = ( User ) s.createCriteria( User.class ) u = s.bySimpleNaturalId( User.class ).load( "steve" );
.add( Restrictions.naturalId().set( "userName", "steve" ) )
.setCacheable( true )
.uniqueResult();
assertNotNull( u ); assertNotNull( u );
assertEquals( 1, sessionFactory().getStatistics().getNaturalIdQueryExecutionCount() ); //0: incorrect stats since hbm.xml can't enable NaturalId caching assertEquals( 1, sessionFactory().getStatistics().getNaturalIdQueryExecutionCount() ); //0: incorrect stats since hbm.xml can't enable NaturalId caching
assertEquals( 0, sessionFactory().getStatistics().getNaturalIdCacheHitCount() ); //1: no stats since hbm.xml can't enable NaturalId caching assertEquals( 0, sessionFactory().getStatistics().getNaturalIdCacheHitCount() ); //1: no stats since hbm.xml can't enable NaturalId caching

View File

@ -8,19 +8,18 @@ package org.hibernate.test.naturalid.mutable;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import org.junit.Test;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.LockOptions; import org.hibernate.LockOptions;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.criterion.Restrictions;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.tuple.entity.EntityMetamodel; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
@ -172,14 +171,10 @@ public class MutableNaturalIdTest extends BaseCoreFunctionalTestCase {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
Object nullUser = s.createCriteria(User.class) Object nullUser = s.byNaturalId( User.class )
.add( Restrictions.naturalId() .using( "name", "gavin" )
.set("name", "gavin") .using( "org", "hb" )
.set("org", "hb") .load();
)
.setCacheable(true)
.uniqueResult();
assertNull(nullUser); assertNull(nullUser);
t.commit(); t.commit();
@ -203,13 +198,10 @@ public class MutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
u = (User) s.createCriteria(User.class) u = s.byNaturalId( User.class )
.add( Restrictions.naturalId() .using( "name", "gavin" )
.set("name", "gavin") .using( "org", "hb" )
.set("org", "hb") .load();
)
.setCacheable(true)
.uniqueResult();
assertNotNull(u); assertNotNull(u);
@ -225,12 +217,10 @@ public class MutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
u = (User) s.createCriteria(User.class) u = s.byNaturalId( User.class )
.add( Restrictions.naturalId() .using( "name", "gavin" )
.set("name", "gavin") .using( "org", "hb" )
.set("org", "hb") .load();
).setCacheable(true)
.uniqueResult();
s.delete(u); s.delete(u);
@ -245,13 +235,10 @@ public class MutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
nullUser = s.createCriteria(User.class) nullUser = s.byNaturalId( User.class )
.add( Restrictions.naturalId() .using( "name", "gavin" )
.set("name", "gavin") .using( "org", "hb" )
.set("org", "hb") .load();
)
.setCacheable(true)
.uniqueResult();
assertNull(nullUser); assertNull(nullUser);
@ -276,13 +263,10 @@ public class MutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
u = ( User ) s.createCriteria( User.class ) u = s.byNaturalId( User.class )
.add( Restrictions.naturalId() .using( "name", "gavin" )
.set( "name", "gavin" ) .using( "org", "hb" )
.set( "org", "hb" ) .load();
)
.setCacheable( true )
.uniqueResult();
assertNotNull( u ); assertNotNull( u );
t.commit(); t.commit();
s.close(); s.close();
@ -302,24 +286,18 @@ public class MutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
u = ( User ) s.createCriteria( User.class ) u = s.byNaturalId( User.class )
.add( Restrictions.naturalId() .using( "name", "gavin" )
.set("name", "gavin") .using( "org", "hb" )
.set("org", "hb") .load();
)
.setCacheable( true )
.uniqueResult();
assertNotNull(u); assertNotNull(u);
assertEquals( 1, sessionFactory().getStatistics().getNaturalIdQueryExecutionCount() ); assertEquals( 1, sessionFactory().getStatistics().getNaturalIdQueryExecutionCount() );
assertEquals( 0, sessionFactory().getStatistics().getNaturalIdCacheHitCount() ); assertEquals( 0, sessionFactory().getStatistics().getNaturalIdCacheHitCount() );
u = ( User ) s.createCriteria( User.class ) u = s.byNaturalId( User.class )
.add( Restrictions.naturalId() .using( "name", "gavin" )
.set("name", "gavin") .using( "org", "hb" )
.set("org", "hb") .load();
)
.setCacheable( true )
.uniqueResult();
assertNotNull(u); assertNotNull(u);
assertEquals( 1, sessionFactory().getStatistics().getNaturalIdQueryExecutionCount() ); assertEquals( 1, sessionFactory().getStatistics().getNaturalIdQueryExecutionCount() );
assertEquals( 0, sessionFactory().getStatistics().getNaturalIdCacheHitCount() ); //1: no stats since hbm.xml can't enable NaturalId caching assertEquals( 0, sessionFactory().getStatistics().getNaturalIdCacheHitCount() ); //1: no stats since hbm.xml can't enable NaturalId caching
@ -347,13 +325,10 @@ public class MutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
u = ( User ) s.createCriteria( User.class ) u = s.byNaturalId( User.class )
.add( Restrictions.naturalId() .using( "name", "steve" )
.set("name", "steve") .using( "org", "hb" )
.set("org", "hb") .load();
)
.setCacheable( true )
.uniqueResult();
assertNotNull( u ); assertNotNull( u );
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
@ -366,13 +341,10 @@ public class MutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
u = ( User ) s.createCriteria( User.class ) u = s.byNaturalId( User.class )
.add( Restrictions.naturalId() .using( "name", "steve" )
.set("name", "steve") .using( "org", "hb" )
.set("org", "hb") .load();
)
.setCacheable( true )
.uniqueResult();
assertNotNull( u ); assertNotNull( u );
assertEquals( 1, sessionFactory().getStatistics().getNaturalIdQueryExecutionCount() ); //0: incorrect stats since hbm.xml can't enable NaturalId caching assertEquals( 1, sessionFactory().getStatistics().getNaturalIdQueryExecutionCount() ); //0: incorrect stats since hbm.xml can't enable NaturalId caching
assertEquals( 0, sessionFactory().getStatistics().getNaturalIdCacheHitCount() ); //1: no stats since hbm.xml can't enable NaturalId caching assertEquals( 0, sessionFactory().getStatistics().getNaturalIdCacheHitCount() ); //1: no stats since hbm.xml can't enable NaturalId caching
@ -384,13 +356,10 @@ public class MutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
u = ( User ) s.createCriteria( User.class ) u = s.byNaturalId( User.class )
.add( Restrictions.naturalId() .using( "name", "steve" )
.set("name", "steve") .using( "org", "hb" )
.set("org", "hb") .load();
)
.setCacheable( true )
.uniqueResult();
assertNull( u ); assertNull( u );
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
@ -411,13 +380,10 @@ public class MutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
u = ( User ) s.createCriteria( User.class ) u = s.byNaturalId( User.class )
.add( Restrictions.naturalId() .using( "name", "steve" )
.set("name", "steve") .using( "org", "hb" )
.set("org", "hb") .load();
)
.setCacheable( true )
.uniqueResult();
assertNotNull( u ); assertNotNull( u );
assertEquals( 1, sessionFactory().getStatistics().getNaturalIdQueryExecutionCount() ); assertEquals( 1, sessionFactory().getStatistics().getNaturalIdQueryExecutionCount() );
@ -430,13 +396,10 @@ public class MutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
u = ( User ) s.createCriteria( User.class ) u = s.byNaturalId( User.class )
.add( Restrictions.naturalId() .using( "name", "steve" )
.set("name", "steve") .using( "org", "hb" )
.set("org", "hb") .load();
)
.setCacheable( true )
.uniqueResult();
assertNotNull( u ); assertNotNull( u );
assertEquals( 1, sessionFactory().getStatistics().getNaturalIdQueryExecutionCount() ); //0: incorrect stats since hbm.xml can't enable NaturalId caching assertEquals( 1, sessionFactory().getStatistics().getNaturalIdQueryExecutionCount() ); //0: incorrect stats since hbm.xml can't enable NaturalId caching
assertEquals( 0, sessionFactory().getStatistics().getNaturalIdCacheHitCount() ); //1: no stats since hbm.xml can't enable NaturalId caching assertEquals( 0, sessionFactory().getStatistics().getNaturalIdCacheHitCount() ); //1: no stats since hbm.xml can't enable NaturalId caching

View File

@ -6,14 +6,12 @@
*/ */
package org.hibernate.test.propertyref.cachedcollections; package org.hibernate.test.propertyref.cachedcollections;
import org.junit.Test;
import org.hibernate.FetchMode;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -44,7 +42,7 @@ public class CachedPropertyRefCollectionTest extends BaseCoreFunctionalTestCase
// First attempt to load it via PK lookup // First attempt to load it via PK lookup
session = openSession(); session = openSession();
session.beginTransaction(); session.beginTransaction();
ManagedObject obj = (ManagedObject) session.get( ManagedObject.class, 1L ); ManagedObject obj = session.get( ManagedObject.class, 1L );
assertNotNull( obj ); assertNotNull( obj );
assertTrue( Hibernate.isInitialized( obj ) ); assertTrue( Hibernate.isInitialized( obj ) );
obj.getMembers().size(); obj.getMembers().size();
@ -55,11 +53,7 @@ public class CachedPropertyRefCollectionTest extends BaseCoreFunctionalTestCase
// Now try to access it via natural key // Now try to access it via natural key
session = openSession(); session = openSession();
session.beginTransaction(); session.beginTransaction();
Criteria criteria = session.createCriteria( ManagedObject.class ) obj = session.bySimpleNaturalId( ManagedObject.class ).load( "test" );
.add( Restrictions.naturalId().set( "name", "test" ) )
.setCacheable( true )
.setFetchMode( "members", FetchMode.JOIN );
obj = (ManagedObject) criteria.uniqueResult();
assertNotNull( obj ); assertNotNull( obj );
assertTrue( Hibernate.isInitialized( obj ) ); assertTrue( Hibernate.isInitialized( obj ) );
obj.getMembers().size(); obj.getMembers().size();

View File

@ -12,6 +12,13 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Root;
import org.junit.Test; import org.junit.Test;
import org.hibernate.CacheMode; import org.hibernate.CacheMode;
@ -25,7 +32,10 @@ import org.hibernate.cfg.Environment;
import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.query.criteria.JpaCriteriaQuery;
import org.hibernate.transform.AliasToBeanConstructorResultTransformer; import org.hibernate.transform.AliasToBeanConstructorResultTransformer;
import org.hibernate.transform.AliasToEntityMapResultTransformer;
import org.hibernate.transform.ResultTransformer; import org.hibernate.transform.ResultTransformer;
import org.hibernate.transform.Transformers; import org.hibernate.transform.Transformers;
import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.StandardBasicTypes;
@ -65,11 +75,28 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
} }
protected abstract class CriteriaExecutor extends QueryExecutor { protected abstract class CriteriaExecutor extends QueryExecutor {
protected abstract Criteria getCriteria(Session s) throws Exception; protected abstract JpaCriteriaQuery<?> getCriteria(Session s) throws Exception;
protected ResultTransformer getResultTransformer() {
return AliasToEntityMapResultTransformer.INSTANCE;
}
@Override @Override
protected Object getResults(Session s, boolean isSingleResult) throws Exception { protected Object getResults(Session s, boolean isSingleResult) throws Exception {
Criteria criteria = getCriteria( s ).setCacheable( getQueryCacheMode() != CacheMode.IGNORE ).setCacheMode( getQueryCacheMode() ); final CacheMode cacheMode = getQueryCacheMode();
return ( isSingleResult ? criteria.uniqueResult() : criteria.list() );
final JpaCriteriaQuery<?> criteria = getCriteria( s );
final Query<?> query = s.createQuery( criteria ).setCacheMode( cacheMode );
if ( cacheMode != CacheMode.IGNORE ) {
query.setCacheable( true );
}
if ( getResultTransformer() != null ) {
query.setResultTransformer( getResultTransformer() );
}
return ( isSingleResult ? query.uniqueResult() : query.list() );
} }
} }
@ -193,14 +220,20 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
public void testAliasToEntityMapNoProjectionList() throws Exception { public void testAliasToEntityMapNoProjectionList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
@Override @Override
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Student.class, "s" ) final CriteriaBuilder builder = s.getSessionFactory().getCriteriaBuilder();
.createAlias( "s.enrolments", "e", CriteriaSpecification.LEFT_JOIN )
.createAlias( "e.course", "c", CriteriaSpecification.LEFT_JOIN ) final JpaCriteriaQuery<Student> criteria = (JpaCriteriaQuery<Student>) builder.createQuery( Student.class );
.setResultTransformer( CriteriaSpecification.ALIAS_TO_ENTITY_MAP )
.addOrder( Order.asc( "s.studentNumber") ); final Root<Student> studentRoot = criteria.from( Student.class );
studentRoot.join( "enrolments", JoinType.LEFT ).join( "course", JoinType.LEFT );
criteria.orderBy( builder.asc( studentRoot.get( "studentNumber" ) ) );
return criteria;
} }
}; };
HqlExecutor hqlExecutor = new HqlExecutor() { HqlExecutor hqlExecutor = new HqlExecutor() {
@Override @Override
public Query getQuery(Session s) { public Query getQuery(Session s) {
@ -208,6 +241,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
.setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP ); .setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
} }
}; };
ResultChecker checker = new ResultChecker() { ResultChecker checker = new ResultChecker() {
public void check(Object results) { public void check(Object results) {
List resultList = ( List ) results; List resultList = ( List ) results;
@ -232,12 +266,18 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
public void testAliasToEntityMapNoProjectionMultiAndNullList() throws Exception { public void testAliasToEntityMapNoProjectionMultiAndNullList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
@Override @Override
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Student.class, "s" ) final CriteriaBuilder builder = s.getSessionFactory().getCriteriaBuilder();
.createAlias( "s.preferredCourse", "p", CriteriaSpecification.LEFT_JOIN )
.createAlias( "s.addresses", "a", CriteriaSpecification.LEFT_JOIN ) final JpaCriteriaQuery<Student> criteria = (JpaCriteriaQuery<Student>) builder.createQuery( Student.class );
.setResultTransformer( CriteriaSpecification.ALIAS_TO_ENTITY_MAP )
.addOrder( Order.asc( "s.studentNumber" ) ); final Root<Student> studentRoot = criteria.from( Student.class );
studentRoot.join( "preferredCourse", JoinType.LEFT );
studentRoot.join( "addresses", JoinType.LEFT );
criteria.orderBy( builder.asc( studentRoot.get( "studentNumber" ) ) );
return criteria;
} }
}; };
HqlExecutor hqlExecutor = new HqlExecutor() { HqlExecutor hqlExecutor = new HqlExecutor() {
@ -282,7 +322,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
public void testAliasToEntityMapNoProjectionNullAndNonNullAliasList() throws Exception { public void testAliasToEntityMapNoProjectionNullAndNonNullAliasList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
@Override @Override
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createAlias( "s.addresses", "a", CriteriaSpecification.LEFT_JOIN ) .createAlias( "s.addresses", "a", CriteriaSpecification.LEFT_JOIN )
.setResultTransformer( CriteriaSpecification.ALIAS_TO_ENTITY_MAP ) .setResultTransformer( CriteriaSpecification.ALIAS_TO_ENTITY_MAP )
@ -323,7 +363,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testEntityWithNonLazyOneToManyUnique() throws Exception { public void testEntityWithNonLazyOneToManyUnique() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Course.class ); return s.createCriteria( Course.class );
} }
@ -347,7 +387,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testEntityWithNonLazyManyToOneList() throws Exception { public void testEntityWithNonLazyManyToOneList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( CourseMeeting.class ) return s.createCriteria( CourseMeeting.class )
.addOrder( Order.asc( "id.day" ) ); .addOrder( Order.asc( "id.day" ) );
@ -376,7 +416,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testEntityWithLazyAssnUnique() throws Exception { public void testEntityWithLazyAssnUnique() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.add( Restrictions.eq( "studentNumber", shermanExpected.getStudentNumber() ) ); .add( Restrictions.eq( "studentNumber", shermanExpected.getStudentNumber() ) );
@ -403,7 +443,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testEntityWithLazyAssnList() throws Exception { public void testEntityWithLazyAssnList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class ) return s.createCriteria( Student.class )
.addOrder( Order.asc( "studentNumber" ) ); .addOrder( Order.asc( "studentNumber" ) );
@ -437,7 +477,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
public void testEntityWithUnaliasedJoinFetchedLazyOneToManySingleElementList() throws Exception { public void testEntityWithUnaliasedJoinFetchedLazyOneToManySingleElementList() throws Exception {
// unaliased // unaliased
CriteriaExecutor criteriaExecutorUnaliased = new CriteriaExecutor() { CriteriaExecutor criteriaExecutorUnaliased = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.setFetchMode( "enrolments", FetchMode.JOIN ) .setFetchMode( "enrolments", FetchMode.JOIN )
@ -473,7 +513,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testJoinWithFetchJoinListCriteria() throws Exception { public void testJoinWithFetchJoinListCriteria() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createAlias( "s.preferredCourse", "pc", Criteria.LEFT_JOIN ) .createAlias( "s.preferredCourse", "pc", Criteria.LEFT_JOIN )
.setFetchMode( "enrolments", FetchMode.JOIN ) .setFetchMode( "enrolments", FetchMode.JOIN )
@ -689,7 +729,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testEntityWithSelectFetchedLazyOneToManySingleElementListCriteria() throws Exception { public void testEntityWithSelectFetchedLazyOneToManySingleElementListCriteria() throws Exception {
CriteriaExecutor criteriaExecutorUnaliased = new CriteriaExecutor() { CriteriaExecutor criteriaExecutorUnaliased = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.setFetchMode( "enrolments", FetchMode.SELECT ) .setFetchMode( "enrolments", FetchMode.SELECT )
@ -716,7 +756,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
public void testEntityWithJoinFetchedLazyOneToManyMultiAndNullElementList() throws Exception { public void testEntityWithJoinFetchedLazyOneToManyMultiAndNullElementList() throws Exception {
//unaliased //unaliased
CriteriaExecutor criteriaExecutorUnaliased = new CriteriaExecutor() { CriteriaExecutor criteriaExecutorUnaliased = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.setFetchMode( "addresses", FetchMode.JOIN ) .setFetchMode( "addresses", FetchMode.JOIN )
@ -731,7 +771,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
//aliased //aliased
CriteriaExecutor criteriaExecutorAliased1 = new CriteriaExecutor() { CriteriaExecutor criteriaExecutorAliased1 = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createAlias( "s.addresses", "a", Criteria.LEFT_JOIN ) .createAlias( "s.addresses", "a", Criteria.LEFT_JOIN )
@ -740,7 +780,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
} }
}; };
CriteriaExecutor criteriaExecutorAliased2 = new CriteriaExecutor() { CriteriaExecutor criteriaExecutorAliased2 = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createAlias( "s.addresses", "a", Criteria.LEFT_JOIN ) .createAlias( "s.addresses", "a", Criteria.LEFT_JOIN )
@ -749,7 +789,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
} }
}; };
CriteriaExecutor criteriaExecutorAliased3 = new CriteriaExecutor() { CriteriaExecutor criteriaExecutorAliased3 = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createCriteria( "s.addresses", "a", Criteria.LEFT_JOIN ) .createCriteria( "s.addresses", "a", Criteria.LEFT_JOIN )
@ -758,7 +798,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
} }
}; };
CriteriaExecutor criteriaExecutorAliased4 = new CriteriaExecutor() { CriteriaExecutor criteriaExecutorAliased4 = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createCriteria( "s.addresses", "a", Criteria.LEFT_JOIN ) .createCriteria( "s.addresses", "a", Criteria.LEFT_JOIN )
@ -800,7 +840,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
public void testEntityWithJoinFetchedLazyManyToOneList() throws Exception { public void testEntityWithJoinFetchedLazyManyToOneList() throws Exception {
// unaliased // unaliased
CriteriaExecutor criteriaExecutorUnaliased = new CriteriaExecutor() { CriteriaExecutor criteriaExecutorUnaliased = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.setFetchMode( "preferredCourse", FetchMode.JOIN ) .setFetchMode( "preferredCourse", FetchMode.JOIN )
@ -815,7 +855,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
// aliased // aliased
CriteriaExecutor criteriaExecutorAliased1 = new CriteriaExecutor() { CriteriaExecutor criteriaExecutorAliased1 = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createAlias( "s.preferredCourse", "pCourse", Criteria.LEFT_JOIN ) .createAlias( "s.preferredCourse", "pCourse", Criteria.LEFT_JOIN )
@ -824,7 +864,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
} }
}; };
CriteriaExecutor criteriaExecutorAliased2 = new CriteriaExecutor() { CriteriaExecutor criteriaExecutorAliased2 = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createAlias( "s.preferredCourse", "pCourse", Criteria.LEFT_JOIN ) .createAlias( "s.preferredCourse", "pCourse", Criteria.LEFT_JOIN )
@ -833,7 +873,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
} }
}; };
CriteriaExecutor criteriaExecutorAliased3 = new CriteriaExecutor() { CriteriaExecutor criteriaExecutorAliased3 = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createCriteria( "s.preferredCourse", "pCourse", Criteria.LEFT_JOIN ) .createCriteria( "s.preferredCourse", "pCourse", Criteria.LEFT_JOIN )
@ -842,7 +882,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
} }
}; };
CriteriaExecutor criteriaExecutorAliased4 = new CriteriaExecutor() { CriteriaExecutor criteriaExecutorAliased4 = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createCriteria( "s.preferredCourse", "pCourse", Criteria.LEFT_JOIN ) .createCriteria( "s.preferredCourse", "pCourse", Criteria.LEFT_JOIN )
@ -878,7 +918,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
public void testEntityWithJoinFetchedLazyManyToOneUsingProjectionList() throws Exception { public void testEntityWithJoinFetchedLazyManyToOneUsingProjectionList() throws Exception {
// unaliased // unaliased
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Enrolment.class, "e" ) return s.createCriteria( Enrolment.class, "e" )
.createAlias( "e.student", "s", Criteria.LEFT_JOIN ) .createAlias( "e.student", "s", Criteria.LEFT_JOIN )
@ -927,7 +967,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testEntityWithJoinedLazyOneToManySingleElementListCriteria() throws Exception { public void testEntityWithJoinedLazyOneToManySingleElementListCriteria() throws Exception {
CriteriaExecutor criteriaExecutorUnaliased = new CriteriaExecutor() { CriteriaExecutor criteriaExecutorUnaliased = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createCriteria( "s.enrolments", Criteria.LEFT_JOIN ) .createCriteria( "s.enrolments", Criteria.LEFT_JOIN )
@ -935,7 +975,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
} }
}; };
CriteriaExecutor criteriaExecutorAliased1 = new CriteriaExecutor() { CriteriaExecutor criteriaExecutorAliased1 = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createCriteria( "s.enrolments", "e", Criteria.LEFT_JOIN ) .createCriteria( "s.enrolments", "e", Criteria.LEFT_JOIN )
@ -943,7 +983,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
} }
}; };
CriteriaExecutor criteriaExecutorAliased2 = new CriteriaExecutor() { CriteriaExecutor criteriaExecutorAliased2 = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createAlias( "s.enrolments", "e", Criteria.LEFT_JOIN ) .createAlias( "s.enrolments", "e", Criteria.LEFT_JOIN )
@ -974,7 +1014,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testEntityWithJoinedLazyOneToManyMultiAndNullListCriteria() throws Exception { public void testEntityWithJoinedLazyOneToManyMultiAndNullListCriteria() throws Exception {
CriteriaExecutor criteriaExecutorUnaliased = new CriteriaExecutor() { CriteriaExecutor criteriaExecutorUnaliased = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createCriteria( "s.addresses", Criteria.LEFT_JOIN ) .createCriteria( "s.addresses", Criteria.LEFT_JOIN )
@ -982,7 +1022,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
} }
}; };
CriteriaExecutor criteriaExecutorAliased1 = new CriteriaExecutor() { CriteriaExecutor criteriaExecutorAliased1 = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createCriteria( "s.addresses", "a", Criteria.LEFT_JOIN ) .createCriteria( "s.addresses", "a", Criteria.LEFT_JOIN )
@ -990,7 +1030,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
} }
}; };
CriteriaExecutor criteriaExecutorAliased2 = new CriteriaExecutor() { CriteriaExecutor criteriaExecutorAliased2 = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createAlias( "s.addresses", "a", Criteria.LEFT_JOIN ) .createAlias( "s.addresses", "a", Criteria.LEFT_JOIN )
@ -1022,7 +1062,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testEntityWithJoinedLazyManyToOneListCriteria() throws Exception { public void testEntityWithJoinedLazyManyToOneListCriteria() throws Exception {
CriteriaExecutor criteriaExecutorUnaliased = new CriteriaExecutor() { CriteriaExecutor criteriaExecutorUnaliased = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createCriteria( "s.preferredCourse", Criteria.LEFT_JOIN ) .createCriteria( "s.preferredCourse", Criteria.LEFT_JOIN )
@ -1030,7 +1070,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
} }
}; };
CriteriaExecutor criteriaExecutorAliased1 = new CriteriaExecutor() { CriteriaExecutor criteriaExecutorAliased1 = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createCriteria( "s.preferredCourse", "p", Criteria.LEFT_JOIN ) .createCriteria( "s.preferredCourse", "p", Criteria.LEFT_JOIN )
@ -1038,7 +1078,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
} }
}; };
CriteriaExecutor criteriaExecutorAliased2 = new CriteriaExecutor() { CriteriaExecutor criteriaExecutorAliased2 = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use RootEntityTransformer by default // should use RootEntityTransformer by default
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createAlias( "s.preferredCourse", "p", Criteria.LEFT_JOIN ) .createAlias( "s.preferredCourse", "p", Criteria.LEFT_JOIN )
@ -1159,7 +1199,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testAliasToEntityMapOneProjectionList() throws Exception { public void testAliasToEntityMapOneProjectionList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Enrolment.class, "e" ) return s.createCriteria( Enrolment.class, "e" )
.setProjection( Projections.property( "e.student" ).as( "student" ) ) .setProjection( Projections.property( "e.student" ).as( "student" ) )
.addOrder( Order.asc( "e.studentNumber") ) .addOrder( Order.asc( "e.studentNumber") )
@ -1195,7 +1235,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testAliasToEntityMapMultiProjectionList() throws Exception { public void testAliasToEntityMapMultiProjectionList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Enrolment.class, "e" ) return s.createCriteria( Enrolment.class, "e" )
.setProjection( .setProjection(
Projections.projectionList() Projections.projectionList()
@ -1243,7 +1283,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testAliasToEntityMapMultiProjectionWithNullAliasList() throws Exception { public void testAliasToEntityMapMultiProjectionWithNullAliasList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Enrolment.class, "e" ) return s.createCriteria( Enrolment.class, "e" )
.setProjection( .setProjection(
Projections.projectionList() Projections.projectionList()
@ -1288,7 +1328,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testAliasToEntityMapMultiAggregatedPropProjectionSingleResult() throws Exception { public void testAliasToEntityMapMultiAggregatedPropProjectionSingleResult() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Enrolment.class ) return s.createCriteria( Enrolment.class )
.setProjection( .setProjection(
Projections.projectionList() Projections.projectionList()
@ -1320,7 +1360,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testOneNonEntityProjectionUnique() throws Exception { public void testOneNonEntityProjectionUnique() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use PassThroughTransformer by default // should use PassThroughTransformer by default
return s.createCriteria( Enrolment.class, "e" ) return s.createCriteria( Enrolment.class, "e" )
.setProjection( Projections.property( "e.semester" ) ) .setProjection( Projections.property( "e.semester" ) )
@ -1345,7 +1385,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testOneNonEntityProjectionList() throws Exception { public void testOneNonEntityProjectionList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use PassThroughTransformer by default // should use PassThroughTransformer by default
return s.createCriteria( Enrolment.class, "e" ) return s.createCriteria( Enrolment.class, "e" )
.setProjection( Projections.property( "e.semester" ) ) .setProjection( Projections.property( "e.semester" ) )
@ -1401,7 +1441,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testOneEntityProjectionUnique() throws Exception { public void testOneEntityProjectionUnique() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use PassThroughTransformer by default // should use PassThroughTransformer by default
return s.createCriteria( Enrolment.class ) return s.createCriteria( Enrolment.class )
.setProjection( Projections.property( "student" ) ) .setProjection( Projections.property( "student" ) )
@ -1430,7 +1470,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
public void testOneEntityProjectionList() throws Exception { public void testOneEntityProjectionList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
// should use PassThroughTransformer by default // should use PassThroughTransformer by default
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Enrolment.class, "e" ) return s.createCriteria( Enrolment.class, "e" )
.setProjection( Projections.property( "e.student" ) ) .setProjection( Projections.property( "e.student" ) )
.addOrder( Order.asc( "e.studentNumber") ); .addOrder( Order.asc( "e.studentNumber") );
@ -1458,7 +1498,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testMultiEntityProjectionUnique() throws Exception { public void testMultiEntityProjectionUnique() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use PassThroughTransformer by default // should use PassThroughTransformer by default
return s.createCriteria( Enrolment.class ) return s.createCriteria( Enrolment.class )
.setProjection( .setProjection(
@ -1500,7 +1540,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testMultiEntityProjectionList() throws Exception { public void testMultiEntityProjectionList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use PassThroughTransformer by default // should use PassThroughTransformer by default
return s.createCriteria( Enrolment.class, "e" ) return s.createCriteria( Enrolment.class, "e" )
.setProjection( .setProjection(
@ -1545,7 +1585,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testMultiEntityProjectionAliasedList() throws Exception { public void testMultiEntityProjectionAliasedList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
// should use PassThroughTransformer by default // should use PassThroughTransformer by default
return s.createCriteria( Enrolment.class, "e" ) return s.createCriteria( Enrolment.class, "e" )
.setProjection( .setProjection(
@ -1590,7 +1630,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testSingleAggregatedPropProjectionSingleResult() throws Exception { public void testSingleAggregatedPropProjectionSingleResult() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Enrolment.class ) return s.createCriteria( Enrolment.class )
.setProjection( Projections.min( "studentNumber" ) ); .setProjection( Projections.min( "studentNumber" ) );
} }
@ -1612,7 +1652,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testMultiAggregatedPropProjectionSingleResult() throws Exception { public void testMultiAggregatedPropProjectionSingleResult() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Enrolment.class ) return s.createCriteria( Enrolment.class )
.setProjection( .setProjection(
Projections.projectionList() Projections.projectionList()
@ -1641,7 +1681,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testAliasToBeanDtoOneArgList() throws Exception { public void testAliasToBeanDtoOneArgList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Enrolment.class, "e" ) return s.createCriteria( Enrolment.class, "e" )
.createAlias( "e.student", "st" ) .createAlias( "e.student", "st" )
.createAlias( "e.course", "co" ) .createAlias( "e.course", "co" )
@ -1674,7 +1714,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testAliasToBeanDtoMultiArgList() throws Exception { public void testAliasToBeanDtoMultiArgList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Enrolment.class, "e" ) return s.createCriteria( Enrolment.class, "e" )
.createAlias( "e.student", "st" ) .createAlias( "e.student", "st" )
.createAlias( "e.course", "co" ) .createAlias( "e.course", "co" )
@ -1711,7 +1751,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testMultiProjectionListThenApplyAliasToBean() throws Exception { public void testMultiProjectionListThenApplyAliasToBean() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Enrolment.class, "e" ) return s.createCriteria( Enrolment.class, "e" )
.createAlias( "e.student", "st" ) .createAlias( "e.student", "st" )
.createAlias( "e.course", "co" ) .createAlias( "e.course", "co" )
@ -1755,7 +1795,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testAliasToBeanDtoLiteralArgList() throws Exception { public void testAliasToBeanDtoLiteralArgList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Enrolment.class, "e" ) return s.createCriteria( Enrolment.class, "e" )
.createAlias( "e.student", "st" ) .createAlias( "e.student", "st" )
.createAlias( "e.course", "co" ) .createAlias( "e.course", "co" )
@ -1797,7 +1837,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testAliasToBeanDtoWithNullAliasList() throws Exception { public void testAliasToBeanDtoWithNullAliasList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Enrolment.class, "e" ) return s.createCriteria( Enrolment.class, "e" )
.createAlias( "e.student", "st" ) .createAlias( "e.student", "st" )
.createAlias( "e.course", "co" ) .createAlias( "e.course", "co" )
@ -1835,7 +1875,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testOneSelectNewNoAliasesList() throws Exception { public void testOneSelectNewNoAliasesList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) throws Exception { protected JpaCriteriaQuery getCriteria(Session s) throws Exception {
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.setProjection( Projections.property( "s.name" ) ) .setProjection( Projections.property( "s.name" ) )
.addOrder( Order.asc( "s.studentNumber" ) ) .addOrder( Order.asc( "s.studentNumber" ) )
@ -1868,7 +1908,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testOneSelectNewAliasesList() throws Exception { public void testOneSelectNewAliasesList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) throws Exception { protected JpaCriteriaQuery getCriteria(Session s) throws Exception {
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.setProjection( Projections.property( "s.name" ).as( "name" )) .setProjection( Projections.property( "s.name" ).as( "name" ))
.addOrder( Order.asc( "s.studentNumber" ) ) .addOrder( Order.asc( "s.studentNumber" ) )
@ -1901,7 +1941,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testMultiSelectNewList() throws Exception{ public void testMultiSelectNewList() throws Exception{
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) throws Exception { protected JpaCriteriaQuery getCriteria(Session s) throws Exception {
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.setProjection( .setProjection(
Projections.projectionList() Projections.projectionList()
@ -1938,7 +1978,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testMultiSelectNewWithLiteralList() throws Exception { public void testMultiSelectNewWithLiteralList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) throws Exception { protected JpaCriteriaQuery getCriteria(Session s) throws Exception {
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.setProjection( .setProjection(
Projections.projectionList() Projections.projectionList()
@ -1976,7 +2016,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testMultiSelectNewListList() throws Exception { public void testMultiSelectNewListList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.setProjection( .setProjection(
Projections.projectionList() Projections.projectionList()
@ -2010,7 +2050,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testMultiSelectNewMapUsingAliasesList() throws Exception { public void testMultiSelectNewMapUsingAliasesList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.setProjection( .setProjection(
Projections.projectionList() Projections.projectionList()
@ -2044,7 +2084,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testMultiSelectNewMapUsingAliasesWithFetchJoinList() throws Exception { public void testMultiSelectNewMapUsingAliasesWithFetchJoinList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createAlias( "s.preferredCourse", "pc", Criteria.LEFT_JOIN ) .createAlias( "s.preferredCourse", "pc", Criteria.LEFT_JOIN )
.setFetchMode( "enrolments", FetchMode.JOIN ) .setFetchMode( "enrolments", FetchMode.JOIN )
@ -2081,7 +2121,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testMultiSelectAliasToEntityMapUsingAliasesWithFetchJoinList() throws Exception { public void testMultiSelectAliasToEntityMapUsingAliasesWithFetchJoinList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createAlias( "s.preferredCourse", "pc", Criteria.LEFT_JOIN ) .createAlias( "s.preferredCourse", "pc", Criteria.LEFT_JOIN )
.setFetchMode( "enrolments", FetchMode.JOIN ) .setFetchMode( "enrolments", FetchMode.JOIN )
@ -2149,7 +2189,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testSelectNewMapUsingAliasesList() throws Exception { public void testSelectNewMapUsingAliasesList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.setProjection( .setProjection(
Projections.projectionList() Projections.projectionList()
@ -2183,7 +2223,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testSelectNewEntityConstructorList() throws Exception { public void testSelectNewEntityConstructorList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.setProjection( .setProjection(
Projections.projectionList() Projections.projectionList()
@ -2224,7 +2264,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
@Test @Test
public void testMapKeyList() throws Exception { public void testMapKeyList() throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() { CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
protected Criteria getCriteria(Session s) { protected JpaCriteriaQuery getCriteria(Session s) {
return s.createCriteria( Student.class, "s" ) return s.createCriteria( Student.class, "s" )
.createAlias( "s.addresses", "a" ) .createAlias( "s.addresses", "a" )
.setProjection( Projections.property( "a.addressType" ) ); .setProjection( Projections.property( "a.addressType" ) );

View File

@ -12,15 +12,13 @@ import javax.persistence.Entity;
import javax.persistence.Id; import javax.persistence.Id;
import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.H2Dialect;
import org.hibernate.hql.internal.ast.QuerySyntaxException;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.query.SemanticException;
import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.junit.Test; import org.junit.Test;
import org.jboss.logging.Logger;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -78,7 +76,7 @@ public class JpaFunctionTest extends BaseEntityManagerFunctionalTestCase {
} ); } );
} }
catch ( Exception e ) { catch ( Exception e ) {
assertEquals( QuerySyntaxException.class, e.getCause().getClass() ); assertEquals( SemanticException.class, e.getCause().getClass() );
} }
} }

View File

@ -7,7 +7,6 @@
package org.hibernate.test.tm; package org.hibernate.test.tm;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.transaction.Transaction; import javax.transaction.Transaction;
@ -17,7 +16,6 @@ import org.hibernate.EntityMode;
import org.hibernate.ScrollableResults; import org.hibernate.ScrollableResults;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.criterion.Order;
import org.hibernate.dialect.SQLServerDialect; import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl; import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl;
@ -33,7 +31,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
/** /**
* @author Gavin King * @author Gavin King
@ -109,14 +106,14 @@ public class CMTTest extends BaseNonConfigCoreFunctionalTestCase {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin(); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s1 = openSession(); s1 = openSession();
s1.createCriteria( "Item" ).list(); s1.createQuery( "from Item" ).list();
//foo.put("description", "a big red foo"); //foo.put("description", "a big red foo");
//s1.flush(); //s1.flush();
tx = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend(); tx = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin(); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s2 = openSession(); s2 = openSession();
s2.createCriteria( "Item" ).list(); s2.createQuery( "from Item" ).list();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit(); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx ); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx );
@ -124,7 +121,7 @@ public class CMTTest extends BaseNonConfigCoreFunctionalTestCase {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin(); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s2 = openSession(); s2 = openSession();
s2.createCriteria( "Item" ).list(); s2.createQuery( "from Item" ).list();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit(); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertEquals( 7, sessionFactory().getStatistics().getEntityLoadCount() ); assertEquals( 7, sessionFactory().getStatistics().getEntityLoadCount() );
@ -171,15 +168,13 @@ public class CMTTest extends BaseNonConfigCoreFunctionalTestCase {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin(); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s1 = openSession(); Session s1 = openSession();
List r1 = s1.createCriteria( "Item" ).addOrder( Order.asc( "description" ) ) List r1 = s1.createQuery( "from Item order by description" ).setCacheable( true ).list();
.setCacheable( true ).list();
assertEquals( r1.size(), 2 ); assertEquals( r1.size(), 2 );
Transaction tx1 = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend(); Transaction tx1 = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin(); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s2 = openSession(); Session s2 = openSession();
List r2 = s2.createCriteria( "Item" ).addOrder( Order.asc( "description" ) ) List r2 = s2.createQuery( "from Item order by description" ).setCacheable( true ).list();
.setCacheable( true ).list();
assertEquals( r2.size(), 2 ); assertEquals( r2.size(), 2 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit(); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
@ -199,8 +194,7 @@ public class CMTTest extends BaseNonConfigCoreFunctionalTestCase {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin(); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s3 = openSession(); Session s3 = openSession();
s3.createCriteria( "Item" ).addOrder( Order.asc( "description" ) ) s3.createQuery( "from Item order by description" ).setCacheable( true ).list();
.setCacheable( true ).list();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit(); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 4 ); assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 4 );
@ -216,8 +210,7 @@ public class CMTTest extends BaseNonConfigCoreFunctionalTestCase {
assertEquals( sessionFactory().getStatistics().getUpdateTimestampsCacheMissCount(), 0 ); assertEquals( sessionFactory().getStatistics().getUpdateTimestampsCacheMissCount(), 0 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx4 ); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx4 );
List r4 = s4.createCriteria( "Item" ).addOrder( Order.asc( "description" ) ) List r4 = s4.createQuery( "from Item order by description" ).setCacheable( true ).list();
.setCacheable( true ).list();
assertEquals( r4.size(), 2 ); assertEquals( r4.size(), 2 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit(); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
@ -272,8 +265,7 @@ public class CMTTest extends BaseNonConfigCoreFunctionalTestCase {
// open a new TX and execute a query, this would fill the query cache. // open a new TX and execute a query, this would fill the query cache.
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin(); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s1 = openSession(); Session s1 = openSession();
List r1 = s1.createCriteria( "Item" ).addOrder( Order.asc( "description" ) ) List r1 = s1.createQuery( "from Item order by description" ).setCacheable( true ).list();
.setCacheable( true ).list();
assertEquals( r1.size(), 2 ); assertEquals( r1.size(), 2 );
foo = ( Map ) r1.get( 0 ); foo = ( Map ) r1.get( 0 );
// update data and make query cache stale, but TX is suspended // update data and make query cache stale, but TX is suspended
@ -285,8 +277,7 @@ public class CMTTest extends BaseNonConfigCoreFunctionalTestCase {
// this TX is committed after query // this TX is committed after query
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin(); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s2 = openSession(); Session s2 = openSession();
List r2 = s2.createCriteria( "Item" ).addOrder( Order.asc( "description" ) ) List r2 = s2.createQuery( "from Item order by description" ).setCacheable( true ).list();
.setCacheable( true ).list();
assertEquals( r2.size(), 2 ); assertEquals( r2.size(), 2 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit(); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
@ -321,8 +312,7 @@ public class CMTTest extends BaseNonConfigCoreFunctionalTestCase {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin(); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s3 = openSession(); Session s3 = openSession();
s3.createCriteria( "Item" ).addOrder( Order.asc( "description" ) ) s3.createQuery( "from Item order by description" ).setCacheable( true ).list();
.setCacheable( true ).list();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit(); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertEquals( 0, sessionFactory().getStatistics().getSecondLevelCacheHitCount() ); assertEquals( 0, sessionFactory().getStatistics().getSecondLevelCacheHitCount() );
@ -337,8 +327,7 @@ public class CMTTest extends BaseNonConfigCoreFunctionalTestCase {
assertEquals( 2, sessionFactory().getStatistics().getUpdateTimestampsCacheHitCount() ); assertEquals( 2, sessionFactory().getStatistics().getUpdateTimestampsCacheHitCount() );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx4 ); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx4 );
List r4 = s4.createCriteria( "Item" ).addOrder( Order.asc( "description" ) ) List r4 = s4.createQuery( "from Item order by description" ).setCacheable( true ).list();
.setCacheable( true ).list();
assertEquals( r4.size(), 2 ); assertEquals( r4.size(), 2 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit(); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
@ -422,53 +411,6 @@ public class CMTTest extends BaseNonConfigCoreFunctionalTestCase {
// i verified that is does currently in my debugger... // i verified that is does currently in my debugger...
} }
@Test
public void testCurrentSessionWithIterate() throws Exception {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Map item1 = new HashMap();
item1.put( "name", "Item - 1" );
item1.put( "description", "The first item" );
s.persist( "Item", item1 );
Map item2 = new HashMap();
item2.put( "name", "Item - 2" );
item2.put( "description", "The second item" );
s.persist( "Item", item2 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
// First, test iterating the partial iterator; iterate to past
// the first, but not the second, item
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = sessionFactory().getCurrentSession();
Iterator itr = s.createQuery( "from Item" ).iterate();
if ( !itr.hasNext() ) {
fail( "No results in iterator" );
}
itr.next();
if ( !itr.hasNext() ) {
fail( "Only one result in iterator" );
}
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
// Next, iterate the entire result
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = sessionFactory().getCurrentSession();
itr = s.createQuery( "from Item" ).iterate();
if ( !itr.hasNext() ) {
fail( "No results in iterator" );
}
while ( itr.hasNext() ) {
itr.next();
}
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.createQuery( "delete from Item" ).executeUpdate();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@Test @Test
public void testCurrentSessionWithScroll() throws Exception { public void testCurrentSessionWithScroll() throws Exception {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin(); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/ */
package org.hibernate.test.criterion; package org.hibernate.test.criteria;
import org.hibernate.IrrelevantEntity; import org.hibernate.IrrelevantEntity;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/ */
package org.hibernate.test.criterion; package org.hibernate.test.criteria;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;