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.cfg.AvailableSettings;
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.mapping.PersistentClass;
import org.hibernate.mapping.Property;
@ -349,18 +347,11 @@ public class AttributeConverterTest extends BaseUnitTestCase {
s = sf.openSession();
s.beginTransaction();
entity = (EntityWithConvertibleField) s.load( EntityWithConvertibleField.class, entityID );
entity = s.load( EntityWithConvertibleField.class, entityID );
assertEquals( ConvertibleEnum.VALUE, entity.getConvertibleEnum() );
s.getTransaction().commit();
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.beginTransaction();
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 org.hibernate.cfg.AnnotationBinder;
import org.hibernate.hql.internal.ast.QuerySyntaxException;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.query.SemanticException;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.logger.LoggerInspectionRule;
@ -75,7 +75,7 @@ public class MappedSuperclassInheritanceTest extends BaseEntityManagerFunctional
entityManager.createQuery("from Employee").getResultList();
fail();
} catch (Exception expected) {
QuerySyntaxException rootException = (QuerySyntaxException) ExceptionUtil.rootCause(expected);
SemanticException rootException = (SemanticException) ExceptionUtil.rootCause( expected);
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.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.Basic;
@ -52,14 +50,12 @@ import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;
import javax.persistence.OrderColumn;
import org.hibernate.hql.spi.QueryTranslator;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
/**
* @author Christian Beikov
@ -116,27 +112,28 @@ public class MultiInheritanceImplicitDowncastTest extends BaseCoreFunctionalTest
}
private void testMultiJoinAddition(String hql) {
final HQLQueryPlan plan = sessionFactory().getQueryInterpretationCache().getHQLQueryPlan(
hql,
false,
Collections.EMPTY_MAP
);
assertEquals( 1, plan.getTranslators().length );
final QueryTranslator translator = plan.getTranslators()[0];
final String generatedSql = translator.getSQLString();
int sub1JoinColumnIndex = generatedSql.indexOf( ".base_sub_1" );
assertNotEquals(
"Generated SQL doesn't contain a join for 'base' with 'PolymorphicSub1' via 'base_sub_1':\n" + generatedSql,
-1,
sub1JoinColumnIndex
);
int sub2JoinColumnIndex = generatedSql.indexOf( ".base_sub_2" );
assertNotEquals(
"Generated SQL doesn't contain a join for 'base' with 'PolymorphicSub2' via 'base_sub_2':\n" + generatedSql,
-1,
sub2JoinColumnIndex
);
throw new NotYetImplementedFor6Exception( getClass() );
// final HQLQueryPlan plan = sessionFactory().getQueryInterpretationCache().getHQLQueryPlan(
// hql,
// false,
// Collections.EMPTY_MAP
// );
// assertEquals( 1, plan.getTranslators().length );
// final QueryTranslator translator = plan.getTranslators()[0];
// final String generatedSql = translator.getSQLString();
//
// int sub1JoinColumnIndex = generatedSql.indexOf( ".base_sub_1" );
// assertNotEquals(
// "Generated SQL doesn't contain a join for 'base' with 'PolymorphicSub1' via 'base_sub_1':\n" + generatedSql,
// -1,
// sub1JoinColumnIndex
// );
// int sub2JoinColumnIndex = generatedSql.indexOf( ".base_sub_2" );
// assertNotEquals(
// "Generated SQL doesn't contain a join for 'base' with 'PolymorphicSub2' via 'base_sub_2':\n" + generatedSql,
// -1,
// sub2JoinColumnIndex
// );
}
@MappedSuperclass

View File

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

View File

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

View File

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

View File

@ -8,17 +8,15 @@ package org.hibernate.test.naturalid.immutable;
import javax.persistence.PersistenceException;
import org.junit.Test;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.criterion.Restrictions;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -112,10 +110,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession();
s.beginTransaction();
u = ( User ) s.createCriteria( User.class )
.add( Restrictions.naturalId().set( "userName", "steve" ) )
.setCacheable( true )
.uniqueResult();
u = s.bySimpleNaturalId( User.class ).load( "steve" );
assertNotNull( u );
s.getTransaction().commit();
s.close();
@ -135,17 +130,11 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession();
s.beginTransaction();
u = ( User ) s.createCriteria( User.class )
.add( Restrictions.naturalId().set( "userName", "steve" ) )
.setCacheable( true )
.uniqueResult();
u = s.bySimpleNaturalId( User.class ).load( "steve" );
assertNotNull( u );
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
u = ( User ) s.createCriteria( User.class )
.add( Restrictions.naturalId().set( "userName", "steve" ) )
.setCacheable( true )
.uniqueResult();
u = s.bySimpleNaturalId( User.class ).load( "steve" );
assertNotNull( u );
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
@ -172,10 +161,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession();
s.beginTransaction();
u = ( User ) s.createCriteria( User.class )
.add( Restrictions.naturalId().set( "userName", "steve" ) )
.setCacheable( true )
.uniqueResult();
u = s.bySimpleNaturalId( User.class ).load( "steve" );
assertNotNull( u );
s.getTransaction().commit();
s.close();
@ -188,11 +174,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession();
s.beginTransaction();
u = ( User ) s.createCriteria( User.class )
.add( Restrictions.naturalId().set( "userName", "steve" ) )
.setCacheable( true )
.uniqueResult();
assertNotNull( u );
u = s.bySimpleNaturalId( User.class ).load( "steve" );
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
@ -203,10 +185,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession();
s.beginTransaction();
u = ( User ) s.createCriteria( User.class )
.add( Restrictions.naturalId().set( "userName", "steve" ) )
.setCacheable( true )
.uniqueResult();
u = s.bySimpleNaturalId( User.class ).load( "steve" );
assertNull( u );
s.getTransaction().commit();
s.close();
@ -227,10 +206,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s = openSession();
s.beginTransaction();
u = ( User ) s.createCriteria( User.class )
.add( Restrictions.naturalId().set( "userName", "steve" ) )
.setCacheable( true )
.uniqueResult();
u = s.bySimpleNaturalId( User.class ).load( "steve" );
assertNotNull( u );
assertEquals( 1, sessionFactory().getStatistics().getNaturalIdQueryExecutionCount() );
@ -241,10 +217,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s.getTransaction().commit();
s = openSession();
s.beginTransaction();
u = ( User ) s.createCriteria( User.class )
.add( Restrictions.naturalId().set( "userName", "steve" ) )
.setCacheable( true )
.uniqueResult();
u = s.bySimpleNaturalId( User.class ).load( "steve" );
assertNotNull( u );
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

View File

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

View File

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

View File

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

View File

@ -12,15 +12,13 @@ import javax.persistence.Entity;
import javax.persistence.Id;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.hql.internal.ast.QuerySyntaxException;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.query.SemanticException;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import org.jboss.logging.Logger;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@ -78,7 +76,7 @@ public class JpaFunctionTest extends BaseEntityManagerFunctionalTestCase {
} );
}
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;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.transaction.Transaction;
@ -17,7 +16,6 @@ import org.hibernate.EntityMode;
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.criterion.Order;
import org.hibernate.dialect.SQLServerDialect;
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.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
/**
* @author Gavin King
@ -109,14 +106,14 @@ public class CMTTest extends BaseNonConfigCoreFunctionalTestCase {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s1 = openSession();
s1.createCriteria( "Item" ).list();
s1.createQuery( "from Item" ).list();
//foo.put("description", "a big red foo");
//s1.flush();
tx = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s2 = openSession();
s2.createCriteria( "Item" ).list();
s2.createQuery( "from Item" ).list();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx );
@ -124,7 +121,7 @@ public class CMTTest extends BaseNonConfigCoreFunctionalTestCase {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s2 = openSession();
s2.createCriteria( "Item" ).list();
s2.createQuery( "from Item" ).list();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertEquals( 7, sessionFactory().getStatistics().getEntityLoadCount() );
@ -171,15 +168,13 @@ public class CMTTest extends BaseNonConfigCoreFunctionalTestCase {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s1 = openSession();
List r1 = s1.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
.setCacheable( true ).list();
List r1 = s1.createQuery( "from Item order by description" ).setCacheable( true ).list();
assertEquals( r1.size(), 2 );
Transaction tx1 = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s2 = openSession();
List r2 = s2.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
.setCacheable( true ).list();
List r2 = s2.createQuery( "from Item order by description" ).setCacheable( true ).list();
assertEquals( r2.size(), 2 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
@ -199,8 +194,7 @@ public class CMTTest extends BaseNonConfigCoreFunctionalTestCase {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s3 = openSession();
s3.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
.setCacheable( true ).list();
s3.createQuery( "from Item order by description" ).setCacheable( true ).list();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 4 );
@ -216,8 +210,7 @@ public class CMTTest extends BaseNonConfigCoreFunctionalTestCase {
assertEquals( sessionFactory().getStatistics().getUpdateTimestampsCacheMissCount(), 0 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx4 );
List r4 = s4.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
.setCacheable( true ).list();
List r4 = s4.createQuery( "from Item order by description" ).setCacheable( true ).list();
assertEquals( r4.size(), 2 );
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.
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s1 = openSession();
List r1 = s1.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
.setCacheable( true ).list();
List r1 = s1.createQuery( "from Item order by description" ).setCacheable( true ).list();
assertEquals( r1.size(), 2 );
foo = ( Map ) r1.get( 0 );
// 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
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s2 = openSession();
List r2 = s2.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
.setCacheable( true ).list();
List r2 = s2.createQuery( "from Item order by description" ).setCacheable( true ).list();
assertEquals( r2.size(), 2 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
@ -321,8 +312,7 @@ public class CMTTest extends BaseNonConfigCoreFunctionalTestCase {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s3 = openSession();
s3.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
.setCacheable( true ).list();
s3.createQuery( "from Item order by description" ).setCacheable( true ).list();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertEquals( 0, sessionFactory().getStatistics().getSecondLevelCacheHitCount() );
@ -337,8 +327,7 @@ public class CMTTest extends BaseNonConfigCoreFunctionalTestCase {
assertEquals( 2, sessionFactory().getStatistics().getUpdateTimestampsCacheHitCount() );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx4 );
List r4 = s4.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
.setCacheable( true ).list();
List r4 = s4.createQuery( "from Item order by description" ).setCacheable( true ).list();
assertEquals( r4.size(), 2 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
@ -422,53 +411,6 @@ public class CMTTest extends BaseNonConfigCoreFunctionalTestCase {
// 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
public void testCurrentSessionWithScroll() throws Exception {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();

View File

@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* 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>.
* 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
*/
package org.hibernate.test.criterion;
package org.hibernate.test.criteria;
import org.hibernate.IrrelevantEntity;
import org.hibernate.SessionFactory;

View File

@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* 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>.
* 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
*/
package org.hibernate.test.criterion;
package org.hibernate.test.criteria;
import javax.persistence.Column;
import javax.persistence.Entity;

View File

@ -1,19 +1,19 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* 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>.
*/
package org.hibernate.test.criteria.limitexpression;
public class Country {
private String code;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* 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>.
*/
package org.hibernate.test.criteria.limitexpression;
public class Country {
private String code;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}

View File

@ -1,41 +1,41 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* 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>.
*/
package org.hibernate.test.criteria.limitexpression;
import java.util.Set;
public class Person {
private Long id;
private Set<UsState> states;
private Set<Country> countries;
public Set<UsState> getStates() {
return states;
}
public void setStates(Set<UsState> states) {
this.states = states;
}
public Set<Country> getCountries() {
return countries;
}
public void setCountries(Set<Country> countries) {
this.countries = countries;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* 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>.
*/
package org.hibernate.test.criteria.limitexpression;
import java.util.Set;
public class Person {
private Long id;
private Set<UsState> states;
private Set<Country> countries;
public Set<UsState> getStates() {
return states;
}
public void setStates(Set<UsState> states) {
this.states = states;
}
public Set<Country> getCountries() {
return countries;
}
public void setCountries(Set<Country> countries) {
this.countries = countries;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}

View File

@ -1,19 +1,19 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* 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>.
*/
package org.hibernate.test.criteria.limitexpression;
public class UsState {
private String code;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* 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>.
*/
package org.hibernate.test.criteria.limitexpression;
public class UsState {
private String code;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}

View File

@ -1,28 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.criteria.limitexpression">
<class name="Person" table="person">
<id name="id" column="id" type="long">
<generator class="increment"/>
</id>
<set name="states" table="person_states" inverse="false" lazy="false" fetch="join">
<key column="id_person" not-null="true"/>
<many-to-many class="UsState" column="code_state"/>
</set>
<set name="countries" table="person_countries" inverse="false" lazy="false" fetch="join">
<key column="id_person" not-null="true"/>
<many-to-many class="Country" column="code_country"/>
</set>
</class>
<class name="UsState" table="us_state">
<id column="code" name="code" type="string"/>
</class>
<class name="Country" table="country">
<id column="code" name="code" type="string"/>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.criteria.limitexpression">
<class name="Person" table="person">
<id name="id" column="id" type="long">
<generator class="increment"/>
</id>
<set name="states" table="person_states" inverse="false" lazy="false" fetch="join">
<key column="id_person" not-null="true"/>
<many-to-many class="UsState" column="code_state"/>
</set>
<set name="countries" table="person_countries" inverse="false" lazy="false" fetch="join">
<key column="id_person" not-null="true"/>
<many-to-many class="Country" column="code_country"/>
</set>
</class>
<class name="UsState" table="us_state">
<id column="code" name="code" type="string"/>
</class>
<class name="Country" table="country">
<id column="code" name="code" type="string"/>
</class>
</hibernate-mapping>