HHH-5942 - Migrate to JUnit 4
This commit is contained in:
parent
ed882f68ae
commit
20a120ef6c
|
@ -907,7 +907,7 @@ public final class SessionFactoryImpl
|
||||||
* <li>remove the JNDI binding
|
* <li>remove the JNDI binding
|
||||||
* </ol>
|
* </ol>
|
||||||
*
|
*
|
||||||
* Note: Be aware that the sessionfactory instance still can
|
* Note: Be aware that the sessionFactory instance still can
|
||||||
* be a "heavy" object memory wise after close() has been called. Thus
|
* be a "heavy" object memory wise after close() has been called. Thus
|
||||||
* it is important to not keep referencing the instance to let the garbage
|
* it is important to not keep referencing the instance to let the garbage
|
||||||
* collector release the memory.
|
* collector release the memory.
|
||||||
|
|
|
@ -23,13 +23,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.annotations.reflection;
|
package org.hibernate.test.annotations.reflection;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import javax.persistence.AssociationOverrides;
|
import javax.persistence.AssociationOverrides;
|
||||||
import javax.persistence.AttributeOverrides;
|
import javax.persistence.AttributeOverrides;
|
||||||
import javax.persistence.Basic;
|
import javax.persistence.Basic;
|
||||||
|
@ -77,48 +70,41 @@ import javax.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
import javax.persistence.Transient;
|
import javax.persistence.Transient;
|
||||||
import javax.persistence.Version;
|
import javax.persistence.Version;
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.dom4j.DocumentException;
|
import org.dom4j.DocumentException;
|
||||||
import org.dom4j.io.SAXReader;
|
import org.dom4j.io.SAXReader;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
import org.xml.sax.SAXNotSupportedException;
|
||||||
|
|
||||||
import org.hibernate.annotations.Columns;
|
import org.hibernate.annotations.Columns;
|
||||||
import org.hibernate.cfg.EJB3DTDEntityResolver;
|
import org.hibernate.cfg.EJB3DTDEntityResolver;
|
||||||
import org.hibernate.cfg.annotations.reflection.JPAOverridenAnnotationReader;
|
import org.hibernate.cfg.annotations.reflection.JPAOverridenAnnotationReader;
|
||||||
import org.hibernate.cfg.annotations.reflection.XMLContext;
|
import org.hibernate.cfg.annotations.reflection.XMLContext;
|
||||||
import org.hibernate.internal.util.xml.XMLHelper;
|
import org.hibernate.internal.util.xml.XMLHelper;
|
||||||
import org.hibernate.testing.junit.functional.annotations.HibernateTestCase;
|
|
||||||
import org.xml.sax.InputSource;
|
import org.junit.Test;
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
import org.xml.sax.SAXNotSupportedException;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
|
public class JPAOverridenAnnotationReaderTest extends BaseUnitTestCase {
|
||||||
|
@Test
|
||||||
@Override
|
|
||||||
protected void buildConfiguration() throws Exception {
|
|
||||||
//Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void runSchemaGeneration() {
|
|
||||||
//Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void runSchemaDrop() {
|
|
||||||
//Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void handleUnclosedResources() {
|
|
||||||
//Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
|
||||||
return new Class<?>[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testMappedSuperclassAnnotations() throws Exception {
|
public void testMappedSuperclassAnnotations() throws Exception {
|
||||||
XMLContext context = buildContext(
|
XMLContext context = buildContext(
|
||||||
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
||||||
|
@ -127,6 +113,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
|
||||||
assertTrue( reader.isAnnotationPresent( MappedSuperclass.class ) );
|
assertTrue( reader.isAnnotationPresent( MappedSuperclass.class ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEntityRelatedAnnotations() throws Exception {
|
public void testEntityRelatedAnnotations() throws Exception {
|
||||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||||
JPAOverridenAnnotationReader reader = new JPAOverridenAnnotationReader( Administration.class, context );
|
JPAOverridenAnnotationReader reader = new JPAOverridenAnnotationReader( Administration.class, context );
|
||||||
|
@ -257,6 +244,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEntityRelatedAnnotationsMetadataComplete() throws Exception {
|
public void testEntityRelatedAnnotationsMetadataComplete() throws Exception {
|
||||||
XMLContext context = buildContext(
|
XMLContext context = buildContext(
|
||||||
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
||||||
|
@ -296,6 +284,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
|
||||||
assertNull( reader.getAnnotation( TableGenerator.class ) );
|
assertNull( reader.getAnnotation( TableGenerator.class ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testIdRelatedAnnotations() throws Exception {
|
public void testIdRelatedAnnotations() throws Exception {
|
||||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||||
Method method = Administration.class.getDeclaredMethod( "getId" );
|
Method method = Administration.class.getDeclaredMethod( "getId" );
|
||||||
|
@ -342,6 +331,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
|
||||||
assertEquals( 1, reader.getAnnotation( AttributeOverrides.class ).value().length );
|
assertEquals( 1, reader.getAnnotation( AttributeOverrides.class ).value().length );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBasicRelatedAnnotations() throws Exception {
|
public void testBasicRelatedAnnotations() throws Exception {
|
||||||
XMLContext context = buildContext(
|
XMLContext context = buildContext(
|
||||||
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
||||||
|
@ -366,6 +356,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
|
||||||
assertNotNull( reader.isAnnotationPresent( Basic.class ) );
|
assertNotNull( reader.isAnnotationPresent( Basic.class ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testVersionRelatedAnnotations() throws Exception {
|
public void testVersionRelatedAnnotations() throws Exception {
|
||||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||||
Method method = Administration.class.getDeclaredMethod( "getVersion" );
|
Method method = Administration.class.getDeclaredMethod( "getVersion" );
|
||||||
|
@ -377,6 +368,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
|
||||||
assertNotNull( reader.getAnnotation( Version.class ) );
|
assertNotNull( reader.getAnnotation( Version.class ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTransientAndEmbeddedRelatedAnnotations() throws Exception {
|
public void testTransientAndEmbeddedRelatedAnnotations() throws Exception {
|
||||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||||
|
|
||||||
|
@ -390,6 +382,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
|
||||||
assertNotNull( reader.getAnnotation( Embedded.class ) );
|
assertNotNull( reader.getAnnotation( Embedded.class ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAssociationRelatedAnnotations() throws Exception {
|
public void testAssociationRelatedAnnotations() throws Exception {
|
||||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||||
|
|
||||||
|
@ -427,6 +420,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
|
||||||
assertEquals( "maxSpeed", reader.getAnnotation( OrderBy.class ).value() );
|
assertEquals( "maxSpeed", reader.getAnnotation( OrderBy.class ).value() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEntityListeners() throws Exception {
|
public void testEntityListeners() throws Exception {
|
||||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.hibernate.test.annotations.xml.ejb3;
|
package org.hibernate.test.annotations.xml.ejb3;
|
||||||
|
|
||||||
import javax.persistence.Access;
|
import javax.persistence.Access;
|
||||||
import javax.persistence.AccessType;
|
import javax.persistence.AccessType;
|
||||||
import javax.persistence.AssociationOverride;
|
import javax.persistence.AssociationOverride;
|
||||||
|
@ -51,8 +52,14 @@ import javax.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
import javax.persistence.UniqueConstraint;
|
import javax.persistence.UniqueConstraint;
|
||||||
|
|
||||||
public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
|
@Test
|
||||||
public void testNoChildren() throws Exception {
|
public void testNoChildren() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "element-collection.orm1.xml" );
|
reader = getReader( Entity2.class, "field1", "element-collection.orm1.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -80,6 +87,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( void.class, relAnno.targetClass() );
|
assertEquals( void.class, relAnno.targetClass() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOrderBy() throws Exception {
|
public void testOrderBy() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "element-collection.orm2.xml" );
|
reader = getReader( Entity2.class, "field1", "element-collection.orm2.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -91,6 +99,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOrderColumnNoAttributes() throws Exception {
|
public void testOrderColumnNoAttributes() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "element-collection.orm3.xml" );
|
reader = getReader( Entity2.class, "field1", "element-collection.orm3.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -104,6 +113,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
assertTrue( orderColumnAnno.updatable() );
|
assertTrue( orderColumnAnno.updatable() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOrderColumnAllAttributes() throws Exception {
|
public void testOrderColumnAllAttributes() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "element-collection.orm4.xml" );
|
reader = getReader( Entity2.class, "field1", "element-collection.orm4.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -117,6 +127,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
assertFalse( orderColumnAnno.updatable() );
|
assertFalse( orderColumnAnno.updatable() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMapKeyNoAttributes() throws Exception {
|
public void testMapKeyNoAttributes() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm5.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm5.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -130,6 +141,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "", reader.getAnnotation( MapKey.class ).name() );
|
assertEquals( "", reader.getAnnotation( MapKey.class ).name() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMapKeyAllAttributes() throws Exception {
|
public void testMapKeyAllAttributes() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm6.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm6.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -143,6 +155,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "field2", reader.getAnnotation( MapKey.class ).name() );
|
assertEquals( "field2", reader.getAnnotation( MapKey.class ).name() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMapKeyClass() throws Exception {
|
public void testMapKeyClass() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm7.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm7.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -159,6 +172,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMapKeyTemporal() throws Exception {
|
public void testMapKeyTemporal() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm8.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm8.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -176,6 +190,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMapKeyEnumerated() throws Exception {
|
public void testMapKeyEnumerated() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm9.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm9.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -197,6 +212,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
* When there's a single map key attribute override, we still wrap it with
|
* When there's a single map key attribute override, we still wrap it with
|
||||||
* an AttributeOverrides annotation.
|
* an AttributeOverrides annotation.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSingleMapKeyAttributeOverride() throws Exception {
|
public void testSingleMapKeyAttributeOverride() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm10.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm10.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -217,6 +233,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "col1", overrides[0].column().name() );
|
assertEquals( "col1", overrides[0].column().name() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMultipleMapKeyAttributeOverrides() throws Exception {
|
public void testMultipleMapKeyAttributeOverrides() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm11.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm11.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -257,6 +274,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( 1, overrides[1].column().scale() );
|
assertEquals( 1, overrides[1].column().scale() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMapKeyColumnNoAttributes() throws Exception {
|
public void testMapKeyColumnNoAttributes() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm12.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm12.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -280,6 +298,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( 0, keyColAnno.scale() );
|
assertEquals( 0, keyColAnno.scale() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMapKeyColumnAllAttributes() throws Exception {
|
public void testMapKeyColumnAllAttributes() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm13.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm13.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -307,6 +326,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
* When there's a single map key join column, we still wrap it with a
|
* When there's a single map key join column, we still wrap it with a
|
||||||
* MapKeyJoinColumns annotation.
|
* MapKeyJoinColumns annotation.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSingleMapKeyJoinColumn() throws Exception {
|
public void testSingleMapKeyJoinColumn() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm14.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm14.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -324,6 +344,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "col1", joinColumns[0].name() );
|
assertEquals( "col1", joinColumns[0].name() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMultipleMapKeyJoinColumns() throws Exception {
|
public void testMultipleMapKeyJoinColumns() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm15.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm15.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -356,6 +377,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "table1", joinColumns[1].table() );
|
assertEquals( "table1", joinColumns[1].table() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testColumnNoAttributes() throws Exception {
|
public void testColumnNoAttributes() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm16.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm16.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -373,6 +395,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( 0, column.scale() );
|
assertEquals( 0, column.scale() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testColumnAllAttributes() throws Exception {
|
public void testColumnAllAttributes() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm17.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm17.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -390,6 +413,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( 1, column.scale() );
|
assertEquals( 1, column.scale() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTemporal() throws Exception {
|
public void testTemporal() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm18.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm18.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -403,6 +427,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEnumerated() throws Exception {
|
public void testEnumerated() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm19.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm19.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -416,6 +441,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testLob() throws Exception {
|
public void testLob() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm20.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm20.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -428,6 +454,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
* When there's a single attribute override, we still wrap it with an
|
* When there's a single attribute override, we still wrap it with an
|
||||||
* AttributeOverrides annotation.
|
* AttributeOverrides annotation.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSingleAttributeOverride() throws Exception {
|
public void testSingleAttributeOverride() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm21.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm21.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -441,6 +468,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "col1", overrides[0].column().name() );
|
assertEquals( "col1", overrides[0].column().name() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMultipleAttributeOverrides() throws Exception {
|
public void testMultipleAttributeOverrides() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm22.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm22.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -478,6 +506,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
* Tests that map-key-attribute-override and attribute-override elements
|
* Tests that map-key-attribute-override and attribute-override elements
|
||||||
* both end up in the AttributeOverrides annotation.
|
* both end up in the AttributeOverrides annotation.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testMixedAttributeOverrides() throws Exception {
|
public void testMixedAttributeOverrides() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm23.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm23.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -497,6 +526,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
* When there's a single association override, we still wrap it with an
|
* When there's a single association override, we still wrap it with an
|
||||||
* AssociationOverrides annotation.
|
* AssociationOverrides annotation.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSingleAssociationOverride() throws Exception {
|
public void testSingleAssociationOverride() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm24.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm24.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -510,6 +540,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "", overrides[0].joinTable().name() );
|
assertEquals( "", overrides[0].joinTable().name() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMultipleAssociationOverridesJoinColumns() throws Exception {
|
public void testMultipleAssociationOverridesJoinColumns() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm25.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm25.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -603,6 +634,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
assertTrue( joinColumns[1].unique() );
|
assertTrue( joinColumns[1].unique() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCollectionTableNoChildren() throws Exception {
|
public void testCollectionTableNoChildren() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm26.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm26.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -615,6 +647,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( 0, tableAnno.uniqueConstraints().length );
|
assertEquals( 0, tableAnno.uniqueConstraints().length );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCollectionTableAllChildren() throws Exception {
|
public void testCollectionTableAllChildren() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "element-collection.orm27.xml" );
|
reader = getReader( Entity3.class, "field1", "element-collection.orm27.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
@ -656,6 +689,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "col5", uniqueConstraints[1].columnNames()[1] );
|
assertEquals( "col5", uniqueConstraints[1].columnNames()[1] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAllAttributes() throws Exception {
|
public void testAllAttributes() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "element-collection.orm28.xml" );
|
reader = getReader( Entity2.class, "field1", "element-collection.orm28.xml" );
|
||||||
assertAnnotationPresent( ElementCollection.class );
|
assertAnnotationPresent( ElementCollection.class );
|
||||||
|
|
|
@ -21,8 +21,8 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.hibernate.test.annotations.xml.ejb3;
|
package org.hibernate.test.annotations.xml.ejb3;
|
||||||
|
|
||||||
import javax.persistence.Access;
|
import javax.persistence.Access;
|
||||||
import javax.persistence.AccessType;
|
import javax.persistence.AccessType;
|
||||||
import javax.persistence.AttributeOverride;
|
import javax.persistence.AttributeOverride;
|
||||||
|
@ -46,8 +46,14 @@ import javax.persistence.OrderColumn;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
import javax.persistence.UniqueConstraint;
|
import javax.persistence.UniqueConstraint;
|
||||||
|
|
||||||
public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||||
|
@Test
|
||||||
public void testNoChildren() throws Exception {
|
public void testNoChildren() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm1.xml" );
|
reader = getReader( Entity2.class, "field1", "many-to-many.orm1.xml" );
|
||||||
assertAnnotationPresent( ManyToMany.class );
|
assertAnnotationPresent( ManyToMany.class );
|
||||||
|
@ -69,6 +75,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( void.class, relAnno.targetEntity() );
|
assertEquals( void.class, relAnno.targetEntity() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOrderBy() throws Exception {
|
public void testOrderBy() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm2.xml" );
|
reader = getReader( Entity2.class, "field1", "many-to-many.orm2.xml" );
|
||||||
assertAnnotationPresent( ManyToMany.class );
|
assertAnnotationPresent( ManyToMany.class );
|
||||||
|
@ -80,6 +87,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOrderColumnNoAttributes() throws Exception {
|
public void testOrderColumnNoAttributes() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm3.xml" );
|
reader = getReader( Entity2.class, "field1", "many-to-many.orm3.xml" );
|
||||||
assertAnnotationPresent( ManyToMany.class );
|
assertAnnotationPresent( ManyToMany.class );
|
||||||
|
@ -93,6 +101,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||||
assertTrue( orderColumnAnno.updatable() );
|
assertTrue( orderColumnAnno.updatable() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOrderColumnAllAttributes() throws Exception {
|
public void testOrderColumnAllAttributes() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm4.xml" );
|
reader = getReader( Entity2.class, "field1", "many-to-many.orm4.xml" );
|
||||||
assertAnnotationPresent( ManyToMany.class );
|
assertAnnotationPresent( ManyToMany.class );
|
||||||
|
@ -106,6 +115,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||||
assertFalse( orderColumnAnno.updatable() );
|
assertFalse( orderColumnAnno.updatable() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMapKeyNoAttributes() throws Exception {
|
public void testMapKeyNoAttributes() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm5.xml" );
|
reader = getReader( Entity3.class, "field1", "many-to-many.orm5.xml" );
|
||||||
assertAnnotationPresent( ManyToMany.class );
|
assertAnnotationPresent( ManyToMany.class );
|
||||||
|
@ -119,6 +129,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "", reader.getAnnotation( MapKey.class ).name() );
|
assertEquals( "", reader.getAnnotation( MapKey.class ).name() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMapKeyAllAttributes() throws Exception {
|
public void testMapKeyAllAttributes() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm6.xml" );
|
reader = getReader( Entity3.class, "field1", "many-to-many.orm6.xml" );
|
||||||
assertAnnotationPresent( ManyToMany.class );
|
assertAnnotationPresent( ManyToMany.class );
|
||||||
|
@ -132,6 +143,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "field2", reader.getAnnotation( MapKey.class ).name() );
|
assertEquals( "field2", reader.getAnnotation( MapKey.class ).name() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMapKeyClass() throws Exception {
|
public void testMapKeyClass() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm7.xml" );
|
reader = getReader( Entity3.class, "field1", "many-to-many.orm7.xml" );
|
||||||
assertAnnotationPresent( ManyToMany.class );
|
assertAnnotationPresent( ManyToMany.class );
|
||||||
|
@ -148,6 +160,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMapKeyTemporal() throws Exception {
|
public void testMapKeyTemporal() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm8.xml" );
|
reader = getReader( Entity3.class, "field1", "many-to-many.orm8.xml" );
|
||||||
assertAnnotationPresent( ManyToMany.class );
|
assertAnnotationPresent( ManyToMany.class );
|
||||||
|
@ -165,6 +178,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMapKeyEnumerated() throws Exception {
|
public void testMapKeyEnumerated() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm9.xml" );
|
reader = getReader( Entity3.class, "field1", "many-to-many.orm9.xml" );
|
||||||
assertAnnotationPresent( ManyToMany.class );
|
assertAnnotationPresent( ManyToMany.class );
|
||||||
|
@ -186,6 +200,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||||
* When there's a single map key attribute override, we still wrap it with
|
* When there's a single map key attribute override, we still wrap it with
|
||||||
* an AttributeOverrides annotation.
|
* an AttributeOverrides annotation.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSingleMapKeyAttributeOverride() throws Exception {
|
public void testSingleMapKeyAttributeOverride() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm10.xml" );
|
reader = getReader( Entity3.class, "field1", "many-to-many.orm10.xml" );
|
||||||
assertAnnotationPresent( ManyToMany.class );
|
assertAnnotationPresent( ManyToMany.class );
|
||||||
|
@ -206,6 +221,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "col1", overrides[0].column().name() );
|
assertEquals( "col1", overrides[0].column().name() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMultipleMapKeyAttributeOverrides() throws Exception {
|
public void testMultipleMapKeyAttributeOverrides() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm11.xml" );
|
reader = getReader( Entity3.class, "field1", "many-to-many.orm11.xml" );
|
||||||
assertAnnotationPresent( ManyToMany.class );
|
assertAnnotationPresent( ManyToMany.class );
|
||||||
|
@ -246,6 +262,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( 1, overrides[1].column().scale() );
|
assertEquals( 1, overrides[1].column().scale() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMapKeyColumnNoAttributes() throws Exception {
|
public void testMapKeyColumnNoAttributes() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm12.xml" );
|
reader = getReader( Entity3.class, "field1", "many-to-many.orm12.xml" );
|
||||||
assertAnnotationPresent( ManyToMany.class );
|
assertAnnotationPresent( ManyToMany.class );
|
||||||
|
@ -269,6 +286,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( 0, keyColAnno.scale() );
|
assertEquals( 0, keyColAnno.scale() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMapKeyColumnAllAttributes() throws Exception {
|
public void testMapKeyColumnAllAttributes() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm13.xml" );
|
reader = getReader( Entity3.class, "field1", "many-to-many.orm13.xml" );
|
||||||
assertAnnotationPresent( ManyToMany.class );
|
assertAnnotationPresent( ManyToMany.class );
|
||||||
|
@ -296,6 +314,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||||
* When there's a single map key join column, we still wrap it with a
|
* When there's a single map key join column, we still wrap it with a
|
||||||
* MapKeyJoinColumns annotation.
|
* MapKeyJoinColumns annotation.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSingleMapKeyJoinColumn() throws Exception {
|
public void testSingleMapKeyJoinColumn() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm14.xml" );
|
reader = getReader( Entity3.class, "field1", "many-to-many.orm14.xml" );
|
||||||
assertAnnotationPresent( ManyToMany.class );
|
assertAnnotationPresent( ManyToMany.class );
|
||||||
|
@ -313,6 +332,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "col1", joinColumns[0].name() );
|
assertEquals( "col1", joinColumns[0].name() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMultipleMapKeyJoinColumns() throws Exception {
|
public void testMultipleMapKeyJoinColumns() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm15.xml" );
|
reader = getReader( Entity3.class, "field1", "many-to-many.orm15.xml" );
|
||||||
assertAnnotationPresent( ManyToMany.class );
|
assertAnnotationPresent( ManyToMany.class );
|
||||||
|
@ -345,6 +365,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "table1", joinColumns[1].table() );
|
assertEquals( "table1", joinColumns[1].table() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testJoinTableNoChildren() throws Exception {
|
public void testJoinTableNoChildren() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm16.xml" );
|
reader = getReader( Entity2.class, "field1", "many-to-many.orm16.xml" );
|
||||||
assertAnnotationPresent( ManyToMany.class );
|
assertAnnotationPresent( ManyToMany.class );
|
||||||
|
@ -360,6 +381,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( 0, joinTableAnno.uniqueConstraints().length );
|
assertEquals( 0, joinTableAnno.uniqueConstraints().length );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testJoinTableAllChildren() throws Exception {
|
public void testJoinTableAllChildren() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm17.xml" );
|
reader = getReader( Entity2.class, "field1", "many-to-many.orm17.xml" );
|
||||||
assertAnnotationPresent( ManyToMany.class );
|
assertAnnotationPresent( ManyToMany.class );
|
||||||
|
@ -424,6 +446,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
|
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCascadeAll() throws Exception {
|
public void testCascadeAll() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm18.xml" );
|
reader = getReader( Entity2.class, "field1", "many-to-many.orm18.xml" );
|
||||||
assertAnnotationPresent( ManyToMany.class );
|
assertAnnotationPresent( ManyToMany.class );
|
||||||
|
@ -432,6 +455,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCascadeSomeWithDefaultPersist() throws Exception {
|
public void testCascadeSomeWithDefaultPersist() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm19.xml" );
|
reader = getReader( Entity2.class, "field1", "many-to-many.orm19.xml" );
|
||||||
assertAnnotationPresent( ManyToMany.class );
|
assertAnnotationPresent( ManyToMany.class );
|
||||||
|
@ -448,6 +472,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||||
* is specified in addition to a default cascade-persist or individual
|
* is specified in addition to a default cascade-persist or individual
|
||||||
* cascade settings.
|
* cascade settings.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testCascadeAllPlusMore() throws Exception {
|
public void testCascadeAllPlusMore() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm20.xml" );
|
reader = getReader( Entity2.class, "field1", "many-to-many.orm20.xml" );
|
||||||
assertAnnotationPresent( ManyToMany.class );
|
assertAnnotationPresent( ManyToMany.class );
|
||||||
|
@ -461,6 +486,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( CascadeType.DETACH, relAnno.cascade()[5] );
|
assertEquals( CascadeType.DETACH, relAnno.cascade()[5] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAllAttributes() throws Exception {
|
public void testAllAttributes() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm21.xml" );
|
reader = getReader( Entity2.class, "field1", "many-to-many.orm21.xml" );
|
||||||
assertAnnotationPresent( ManyToMany.class );
|
assertAnnotationPresent( ManyToMany.class );
|
||||||
|
|
|
@ -21,8 +21,8 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.hibernate.test.annotations.xml.ejb3;
|
package org.hibernate.test.annotations.xml.ejb3;
|
||||||
|
|
||||||
import javax.persistence.Access;
|
import javax.persistence.Access;
|
||||||
import javax.persistence.AccessType;
|
import javax.persistence.AccessType;
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
|
@ -35,8 +35,14 @@ import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.MapsId;
|
import javax.persistence.MapsId;
|
||||||
import javax.persistence.UniqueConstraint;
|
import javax.persistence.UniqueConstraint;
|
||||||
|
|
||||||
public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
|
||||||
|
@Test
|
||||||
public void testNoJoins() throws Exception {
|
public void testNoJoins() throws Exception {
|
||||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm1.xml" );
|
reader = getReader( Entity1.class, "field1", "many-to-one.orm1.xml" );
|
||||||
assertAnnotationPresent( ManyToOne.class );
|
assertAnnotationPresent( ManyToOne.class );
|
||||||
|
@ -57,6 +63,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
|
||||||
* When there's a single join column, we still wrap it with a JoinColumns
|
* When there's a single join column, we still wrap it with a JoinColumns
|
||||||
* annotation.
|
* annotation.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSingleJoinColumn() throws Exception {
|
public void testSingleJoinColumn() throws Exception {
|
||||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm2.xml" );
|
reader = getReader( Entity1.class, "field1", "many-to-one.orm2.xml" );
|
||||||
assertAnnotationPresent( ManyToOne.class );
|
assertAnnotationPresent( ManyToOne.class );
|
||||||
|
@ -71,6 +78,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "table1", joinColumns[0].table() );
|
assertEquals( "table1", joinColumns[0].table() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMultipleJoinColumns() throws Exception {
|
public void testMultipleJoinColumns() throws Exception {
|
||||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm3.xml" );
|
reader = getReader( Entity1.class, "field1", "many-to-one.orm3.xml" );
|
||||||
assertAnnotationPresent( ManyToOne.class );
|
assertAnnotationPresent( ManyToOne.class );
|
||||||
|
@ -98,6 +106,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
|
||||||
assertTrue( joinColumns[1].unique() );
|
assertTrue( joinColumns[1].unique() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testJoinTableNoChildren() throws Exception {
|
public void testJoinTableNoChildren() throws Exception {
|
||||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm4.xml" );
|
reader = getReader( Entity1.class, "field1", "many-to-one.orm4.xml" );
|
||||||
assertAnnotationPresent( ManyToOne.class );
|
assertAnnotationPresent( ManyToOne.class );
|
||||||
|
@ -113,6 +122,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( 0, joinTableAnno.uniqueConstraints().length );
|
assertEquals( 0, joinTableAnno.uniqueConstraints().length );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testJoinTableAllChildren() throws Exception {
|
public void testJoinTableAllChildren() throws Exception {
|
||||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm5.xml" );
|
reader = getReader( Entity1.class, "field1", "many-to-one.orm5.xml" );
|
||||||
assertAnnotationPresent( ManyToOne.class );
|
assertAnnotationPresent( ManyToOne.class );
|
||||||
|
@ -177,6 +187,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
|
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAllAttributes() throws Exception {
|
public void testAllAttributes() throws Exception {
|
||||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm6.xml" );
|
reader = getReader( Entity1.class, "field1", "many-to-one.orm6.xml" );
|
||||||
assertAnnotationPresent( ManyToOne.class );
|
assertAnnotationPresent( ManyToOne.class );
|
||||||
|
@ -198,6 +209,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCascadeAll() throws Exception {
|
public void testCascadeAll() throws Exception {
|
||||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm7.xml" );
|
reader = getReader( Entity1.class, "field1", "many-to-one.orm7.xml" );
|
||||||
assertAnnotationPresent( ManyToOne.class );
|
assertAnnotationPresent( ManyToOne.class );
|
||||||
|
@ -206,6 +218,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCascadeSomeWithDefaultPersist() throws Exception {
|
public void testCascadeSomeWithDefaultPersist() throws Exception {
|
||||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm8.xml" );
|
reader = getReader( Entity1.class, "field1", "many-to-one.orm8.xml" );
|
||||||
assertAnnotationPresent( ManyToOne.class );
|
assertAnnotationPresent( ManyToOne.class );
|
||||||
|
@ -222,6 +235,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
|
||||||
* is specified in addition to a default cascade-persist or individual
|
* is specified in addition to a default cascade-persist or individual
|
||||||
* cascade settings.
|
* cascade settings.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testCascadeAllPlusMore() throws Exception {
|
public void testCascadeAllPlusMore() throws Exception {
|
||||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm9.xml" );
|
reader = getReader( Entity1.class, "field1", "many-to-one.orm9.xml" );
|
||||||
assertAnnotationPresent( ManyToOne.class );
|
assertAnnotationPresent( ManyToOne.class );
|
||||||
|
|
|
@ -21,8 +21,8 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.hibernate.test.annotations.xml.ejb3;
|
package org.hibernate.test.annotations.xml.ejb3;
|
||||||
|
|
||||||
import javax.persistence.Access;
|
import javax.persistence.Access;
|
||||||
import javax.persistence.AccessType;
|
import javax.persistence.AccessType;
|
||||||
import javax.persistence.AttributeOverride;
|
import javax.persistence.AttributeOverride;
|
||||||
|
@ -46,8 +46,14 @@ import javax.persistence.OrderColumn;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
import javax.persistence.UniqueConstraint;
|
import javax.persistence.UniqueConstraint;
|
||||||
|
|
||||||
public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
|
@Test
|
||||||
public void testNoChildren() throws Exception {
|
public void testNoChildren() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm1.xml" );
|
reader = getReader( Entity2.class, "field1", "one-to-many.orm1.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -72,6 +78,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( void.class, relAnno.targetEntity() );
|
assertEquals( void.class, relAnno.targetEntity() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOrderBy() throws Exception {
|
public void testOrderBy() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm2.xml" );
|
reader = getReader( Entity2.class, "field1", "one-to-many.orm2.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -83,6 +90,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOrderColumnNoAttributes() throws Exception {
|
public void testOrderColumnNoAttributes() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm3.xml" );
|
reader = getReader( Entity2.class, "field1", "one-to-many.orm3.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -96,6 +104,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
assertTrue( orderColumnAnno.updatable() );
|
assertTrue( orderColumnAnno.updatable() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOrderColumnAllAttributes() throws Exception {
|
public void testOrderColumnAllAttributes() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm4.xml" );
|
reader = getReader( Entity2.class, "field1", "one-to-many.orm4.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -109,6 +118,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
assertFalse( orderColumnAnno.updatable() );
|
assertFalse( orderColumnAnno.updatable() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMapKeyNoAttributes() throws Exception {
|
public void testMapKeyNoAttributes() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm5.xml" );
|
reader = getReader( Entity3.class, "field1", "one-to-many.orm5.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -122,6 +132,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "", reader.getAnnotation( MapKey.class ).name() );
|
assertEquals( "", reader.getAnnotation( MapKey.class ).name() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMapKeyAllAttributes() throws Exception {
|
public void testMapKeyAllAttributes() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm6.xml" );
|
reader = getReader( Entity3.class, "field1", "one-to-many.orm6.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -135,6 +146,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "field2", reader.getAnnotation( MapKey.class ).name() );
|
assertEquals( "field2", reader.getAnnotation( MapKey.class ).name() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMapKeyClass() throws Exception {
|
public void testMapKeyClass() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm7.xml" );
|
reader = getReader( Entity3.class, "field1", "one-to-many.orm7.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -151,6 +163,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMapKeyTemporal() throws Exception {
|
public void testMapKeyTemporal() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm8.xml" );
|
reader = getReader( Entity3.class, "field1", "one-to-many.orm8.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -168,6 +181,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMapKeyEnumerated() throws Exception {
|
public void testMapKeyEnumerated() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm9.xml" );
|
reader = getReader( Entity3.class, "field1", "one-to-many.orm9.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -189,6 +203,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
* When there's a single map key attribute override, we still wrap it with
|
* When there's a single map key attribute override, we still wrap it with
|
||||||
* an AttributeOverrides annotation.
|
* an AttributeOverrides annotation.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSingleMapKeyAttributeOverride() throws Exception {
|
public void testSingleMapKeyAttributeOverride() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm10.xml" );
|
reader = getReader( Entity3.class, "field1", "one-to-many.orm10.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -209,6 +224,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "col1", overrides[0].column().name() );
|
assertEquals( "col1", overrides[0].column().name() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMultipleMapKeyAttributeOverrides() throws Exception {
|
public void testMultipleMapKeyAttributeOverrides() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm11.xml" );
|
reader = getReader( Entity3.class, "field1", "one-to-many.orm11.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -249,6 +265,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( 1, overrides[1].column().scale() );
|
assertEquals( 1, overrides[1].column().scale() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMapKeyColumnNoAttributes() throws Exception {
|
public void testMapKeyColumnNoAttributes() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm12.xml" );
|
reader = getReader( Entity3.class, "field1", "one-to-many.orm12.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -272,6 +289,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( 0, keyColAnno.scale() );
|
assertEquals( 0, keyColAnno.scale() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMapKeyColumnAllAttributes() throws Exception {
|
public void testMapKeyColumnAllAttributes() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm13.xml" );
|
reader = getReader( Entity3.class, "field1", "one-to-many.orm13.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -299,6 +317,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
* When there's a single map key join column, we still wrap it with a
|
* When there's a single map key join column, we still wrap it with a
|
||||||
* MapKeyJoinColumns annotation.
|
* MapKeyJoinColumns annotation.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSingleMapKeyJoinColumn() throws Exception {
|
public void testSingleMapKeyJoinColumn() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm14.xml" );
|
reader = getReader( Entity3.class, "field1", "one-to-many.orm14.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -316,6 +335,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "col1", joinColumns[0].name() );
|
assertEquals( "col1", joinColumns[0].name() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMultipleMapKeyJoinColumns() throws Exception {
|
public void testMultipleMapKeyJoinColumns() throws Exception {
|
||||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm15.xml" );
|
reader = getReader( Entity3.class, "field1", "one-to-many.orm15.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -348,6 +368,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "table1", joinColumns[1].table() );
|
assertEquals( "table1", joinColumns[1].table() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testJoinTableNoChildren() throws Exception {
|
public void testJoinTableNoChildren() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm16.xml" );
|
reader = getReader( Entity2.class, "field1", "one-to-many.orm16.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -363,6 +384,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( 0, joinTableAnno.uniqueConstraints().length );
|
assertEquals( 0, joinTableAnno.uniqueConstraints().length );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testJoinTableAllChildren() throws Exception {
|
public void testJoinTableAllChildren() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm17.xml" );
|
reader = getReader( Entity2.class, "field1", "one-to-many.orm17.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -431,6 +453,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
* When there's a single join column, we still wrap it with a JoinColumns
|
* When there's a single join column, we still wrap it with a JoinColumns
|
||||||
* annotation.
|
* annotation.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSingleJoinColumn() throws Exception {
|
public void testSingleJoinColumn() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm18.xml" );
|
reader = getReader( Entity2.class, "field1", "one-to-many.orm18.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -445,6 +468,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "table1", joinColumns[0].table() );
|
assertEquals( "table1", joinColumns[0].table() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMultipleJoinColumns() throws Exception {
|
public void testMultipleJoinColumns() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm19.xml" );
|
reader = getReader( Entity2.class, "field1", "one-to-many.orm19.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -472,6 +496,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
assertTrue( joinColumns[1].unique() );
|
assertTrue( joinColumns[1].unique() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCascadeAll() throws Exception {
|
public void testCascadeAll() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm20.xml" );
|
reader = getReader( Entity2.class, "field1", "one-to-many.orm20.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -480,6 +505,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCascadeSomeWithDefaultPersist() throws Exception {
|
public void testCascadeSomeWithDefaultPersist() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm21.xml" );
|
reader = getReader( Entity2.class, "field1", "one-to-many.orm21.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -496,6 +522,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
* is specified in addition to a default cascade-persist or individual
|
* is specified in addition to a default cascade-persist or individual
|
||||||
* cascade settings.
|
* cascade settings.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testCascadeAllPlusMore() throws Exception {
|
public void testCascadeAllPlusMore() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm22.xml" );
|
reader = getReader( Entity2.class, "field1", "one-to-many.orm22.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
@ -509,6 +536,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( CascadeType.DETACH, relAnno.cascade()[5] );
|
assertEquals( CascadeType.DETACH, relAnno.cascade()[5] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAllAttributes() throws Exception {
|
public void testAllAttributes() throws Exception {
|
||||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm23.xml" );
|
reader = getReader( Entity2.class, "field1", "one-to-many.orm23.xml" );
|
||||||
assertAnnotationPresent( OneToMany.class );
|
assertAnnotationPresent( OneToMany.class );
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.hibernate.test.annotations.xml.ejb3;
|
package org.hibernate.test.annotations.xml.ejb3;
|
||||||
|
|
||||||
import javax.persistence.Access;
|
import javax.persistence.Access;
|
||||||
import javax.persistence.AccessType;
|
import javax.persistence.AccessType;
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
|
@ -37,8 +38,14 @@ import javax.persistence.PrimaryKeyJoinColumn;
|
||||||
import javax.persistence.PrimaryKeyJoinColumns;
|
import javax.persistence.PrimaryKeyJoinColumns;
|
||||||
import javax.persistence.UniqueConstraint;
|
import javax.persistence.UniqueConstraint;
|
||||||
|
|
||||||
public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
|
||||||
|
@Test
|
||||||
public void testNoChildren() throws Exception {
|
public void testNoChildren() throws Exception {
|
||||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm1.xml" );
|
reader = getReader( Entity1.class, "field1", "one-to-one.orm1.xml" );
|
||||||
assertAnnotationPresent( OneToOne.class );
|
assertAnnotationPresent( OneToOne.class );
|
||||||
|
@ -63,6 +70,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
|
||||||
* When there's a single primary key join column, we still wrap it with
|
* When there's a single primary key join column, we still wrap it with
|
||||||
* a PrimaryKeyJoinColumns annotation.
|
* a PrimaryKeyJoinColumns annotation.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSinglePrimaryKeyJoinColumn() throws Exception {
|
public void testSinglePrimaryKeyJoinColumn() throws Exception {
|
||||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm2.xml" );
|
reader = getReader( Entity1.class, "field1", "one-to-one.orm2.xml" );
|
||||||
assertAnnotationPresent( OneToOne.class );
|
assertAnnotationPresent( OneToOne.class );
|
||||||
|
@ -80,6 +88,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "int", joinColumns[0].columnDefinition() );
|
assertEquals( "int", joinColumns[0].columnDefinition() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMultiplePrimaryKeyJoinColumn() throws Exception {
|
public void testMultiplePrimaryKeyJoinColumn() throws Exception {
|
||||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm3.xml" );
|
reader = getReader( Entity1.class, "field1", "one-to-one.orm3.xml" );
|
||||||
assertAnnotationPresent( OneToOne.class );
|
assertAnnotationPresent( OneToOne.class );
|
||||||
|
@ -104,6 +113,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
|
||||||
* When there's a single join column, we still wrap it with a JoinColumns
|
* When there's a single join column, we still wrap it with a JoinColumns
|
||||||
* annotation.
|
* annotation.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSingleJoinColumn() throws Exception {
|
public void testSingleJoinColumn() throws Exception {
|
||||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm4.xml" );
|
reader = getReader( Entity1.class, "field1", "one-to-one.orm4.xml" );
|
||||||
assertAnnotationPresent( OneToOne.class );
|
assertAnnotationPresent( OneToOne.class );
|
||||||
|
@ -120,6 +130,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "table1", joinColumns[0].table() );
|
assertEquals( "table1", joinColumns[0].table() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMultipleJoinColumns() throws Exception {
|
public void testMultipleJoinColumns() throws Exception {
|
||||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm5.xml" );
|
reader = getReader( Entity1.class, "field1", "one-to-one.orm5.xml" );
|
||||||
assertAnnotationPresent( OneToOne.class );
|
assertAnnotationPresent( OneToOne.class );
|
||||||
|
@ -149,6 +160,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
|
||||||
assertTrue( joinColumns[1].unique() );
|
assertTrue( joinColumns[1].unique() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testJoinTableNoChildren() throws Exception {
|
public void testJoinTableNoChildren() throws Exception {
|
||||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm6.xml" );
|
reader = getReader( Entity1.class, "field1", "one-to-one.orm6.xml" );
|
||||||
assertAnnotationPresent( OneToOne.class );
|
assertAnnotationPresent( OneToOne.class );
|
||||||
|
@ -166,6 +178,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( 0, joinTableAnno.uniqueConstraints().length );
|
assertEquals( 0, joinTableAnno.uniqueConstraints().length );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testJoinTableAllChildren() throws Exception {
|
public void testJoinTableAllChildren() throws Exception {
|
||||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm7.xml" );
|
reader = getReader( Entity1.class, "field1", "one-to-one.orm7.xml" );
|
||||||
assertAnnotationPresent( OneToOne.class );
|
assertAnnotationPresent( OneToOne.class );
|
||||||
|
@ -232,6 +245,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
|
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCascadeAll() throws Exception {
|
public void testCascadeAll() throws Exception {
|
||||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm8.xml" );
|
reader = getReader( Entity1.class, "field1", "one-to-one.orm8.xml" );
|
||||||
assertAnnotationPresent( OneToOne.class );
|
assertAnnotationPresent( OneToOne.class );
|
||||||
|
@ -240,6 +254,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCascadeSomeWithDefaultPersist() throws Exception {
|
public void testCascadeSomeWithDefaultPersist() throws Exception {
|
||||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm9.xml" );
|
reader = getReader( Entity1.class, "field1", "one-to-one.orm9.xml" );
|
||||||
assertAnnotationPresent( OneToOne.class );
|
assertAnnotationPresent( OneToOne.class );
|
||||||
|
@ -256,6 +271,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
|
||||||
* is specified in addition to a default cascade-persist or individual
|
* is specified in addition to a default cascade-persist or individual
|
||||||
* cascade settings.
|
* cascade settings.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testCascadeAllPlusMore() throws Exception {
|
public void testCascadeAllPlusMore() throws Exception {
|
||||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm10.xml" );
|
reader = getReader( Entity1.class, "field1", "one-to-one.orm10.xml" );
|
||||||
assertAnnotationPresent( OneToOne.class );
|
assertAnnotationPresent( OneToOne.class );
|
||||||
|
@ -269,6 +285,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
|
||||||
assertEquals( CascadeType.DETACH, relAnno.cascade()[5] );
|
assertEquals( CascadeType.DETACH, relAnno.cascade()[5] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAllAttributes() throws Exception {
|
public void testAllAttributes() throws Exception {
|
||||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm11.xml" );
|
reader = getReader( Entity1.class, "field1", "one-to-one.orm11.xml" );
|
||||||
assertAnnotationPresent( OneToOne.class );
|
assertAnnotationPresent( OneToOne.class );
|
||||||
|
|
|
@ -23,48 +23,31 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.hibernate.test.annotations.xml.ejb3;
|
package org.hibernate.test.annotations.xml.ejb3;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.AnnotatedElement;
|
import java.lang.reflect.AnnotatedElement;
|
||||||
|
|
||||||
import org.dom4j.Document;
|
import org.dom4j.Document;
|
||||||
import org.dom4j.io.SAXReader;
|
import org.dom4j.io.SAXReader;
|
||||||
|
|
||||||
import org.hibernate.cfg.annotations.reflection.JPAOverridenAnnotationReader;
|
import org.hibernate.cfg.annotations.reflection.JPAOverridenAnnotationReader;
|
||||||
import org.hibernate.cfg.annotations.reflection.XMLContext;
|
import org.hibernate.cfg.annotations.reflection.XMLContext;
|
||||||
import org.hibernate.testing.junit.functional.annotations.HibernateTestCase;
|
|
||||||
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test superclass to provide utility methods for testing the mapping of JPA
|
* Test superclass to provide utility methods for testing the mapping of JPA
|
||||||
* XML to JPA annotations. The configuration is built within each test, and no
|
* XML to JPA annotations. The configuration is built within each test, and no
|
||||||
* database is used. Thus, no schema generation or cleanup will be performed.
|
* database is used. Thus, no schema generation or cleanup will be performed.
|
||||||
*/
|
*/
|
||||||
abstract class Ejb3XmlTestCase extends HibernateTestCase {
|
abstract class Ejb3XmlTestCase extends BaseUnitTestCase {
|
||||||
protected JPAOverridenAnnotationReader reader;
|
protected JPAOverridenAnnotationReader reader;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void buildConfiguration() throws Exception {
|
|
||||||
//Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void runSchemaGeneration() {
|
|
||||||
//Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void runSchemaDrop() {
|
|
||||||
//Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void handleUnclosedResources() {
|
|
||||||
//Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
|
||||||
return new Class<?>[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void assertAnnotationPresent(Class<? extends Annotation> annotationType) {
|
protected void assertAnnotationPresent(Class<? extends Annotation> annotationType) {
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"Expected annotation " + annotationType.getSimpleName() + " was not present",
|
"Expected annotation " + annotationType.getSimpleName() + " was not present",
|
||||||
|
|
|
@ -45,7 +45,6 @@ import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.testing.FailureExpected;
|
import org.hibernate.testing.FailureExpected;
|
||||||
import org.hibernate.testing.RequiresDialect;
|
import org.hibernate.testing.RequiresDialect;
|
||||||
import org.hibernate.testing.SkipForDialect;
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
|
||||||
|
@ -160,14 +159,14 @@ public class ComponentTest extends BaseCoreFunctionalTestCase {
|
||||||
User u = new User( "steve", "hibernater", new Person( "Steve Ebersole", new Date(), "Main St") );
|
User u = new User( "steve", "hibernater", new Person( "Steve Ebersole", new Date(), "Main St") );
|
||||||
s.persist( u );
|
s.persist( u );
|
||||||
s.flush();
|
s.flush();
|
||||||
long intialUpdateCount = sfi().getStatistics().getEntityUpdateCount();
|
long intialUpdateCount = sessionFactory().getStatistics().getEntityUpdateCount();
|
||||||
u.getPerson().setAddress( "Austin" );
|
u.getPerson().setAddress( "Austin" );
|
||||||
s.flush();
|
s.flush();
|
||||||
assertEquals( intialUpdateCount + 1, sfi().getStatistics().getEntityUpdateCount() );
|
assertEquals( intialUpdateCount + 1, sessionFactory().getStatistics().getEntityUpdateCount() );
|
||||||
intialUpdateCount = sfi().getStatistics().getEntityUpdateCount();
|
intialUpdateCount = sessionFactory().getStatistics().getEntityUpdateCount();
|
||||||
u.getPerson().setAddress( "Cedar Park" );
|
u.getPerson().setAddress( "Cedar Park" );
|
||||||
s.flush();
|
s.flush();
|
||||||
assertEquals( intialUpdateCount + 1, sfi().getStatistics().getEntityUpdateCount() );
|
assertEquals( intialUpdateCount + 1, sessionFactory().getStatistics().getEntityUpdateCount() );
|
||||||
s.delete( u );
|
s.delete( u );
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class HibernateCreateBlobFailedCase extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLobCreation() throws SQLException {
|
public void testLobCreation() throws SQLException {
|
||||||
Session session = sfi().getCurrentSession();
|
Session session = sessionFactory().getCurrentSession();
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
Blob blob = Hibernate.getLobCreator( session ).createBlob( new byte[] {} );
|
Blob blob = Hibernate.getLobCreator( session ).createBlob( new byte[] {} );
|
||||||
blob.free();
|
blob.free();
|
||||||
|
|
|
@ -103,7 +103,7 @@ public class SuppliedConnectionTest extends ConnectionManagementTestCase {
|
||||||
super.prepareTest();
|
super.prepareTest();
|
||||||
Connection conn = cp.getConnection();
|
Connection conn = cp.getConnection();
|
||||||
try {
|
try {
|
||||||
new SchemaExport( getCfg(), conn ).create( false, true );
|
new SchemaExport( configuration(), conn ).create( false, true );
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if ( conn != null ) {
|
if ( conn != null ) {
|
||||||
|
@ -120,7 +120,7 @@ public class SuppliedConnectionTest extends ConnectionManagementTestCase {
|
||||||
protected void cleanupTest() throws Exception {
|
protected void cleanupTest() throws Exception {
|
||||||
Connection conn = cp.getConnection();
|
Connection conn = cp.getConnection();
|
||||||
try {
|
try {
|
||||||
new SchemaExport( getCfg(), conn ).drop( false, true );
|
new SchemaExport( configuration(), conn ).drop( false, true );
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if ( conn != null ) {
|
if ( conn != null ) {
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class ThreadLocalCurrentSessionTest extends ConnectionManagementTestCase
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Session getSessionUnderTest() throws Throwable {
|
protected Session getSessionUnderTest() throws Throwable {
|
||||||
Session session = getSessions().getCurrentSession();
|
Session session = sessionFactory().getCurrentSession();
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
@ -59,12 +59,12 @@ public class ThreadLocalCurrentSessionTest extends ConnectionManagementTestCase
|
||||||
@Override
|
@Override
|
||||||
protected void release(Session session) {
|
protected void release(Session session) {
|
||||||
if ( session.getTransaction().getLocalStatus() != LocalStatus.ACTIVE ) {
|
if ( session.getTransaction().getLocalStatus() != LocalStatus.ACTIVE ) {
|
||||||
TestableThreadLocalContext.unbind( sfi() );
|
TestableThreadLocalContext.unbind( sessionFactory() );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
long initialCount = getSessions().getStatistics().getSessionCloseCount();
|
long initialCount = sessionFactory().getStatistics().getSessionCloseCount();
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
long subsequentCount = getSessions().getStatistics().getSessionCloseCount();
|
long subsequentCount = sessionFactory().getStatistics().getSessionCloseCount();
|
||||||
assertEquals( "Session still open after commit", initialCount + 1, subsequentCount );
|
assertEquals( "Session still open after commit", initialCount + 1, subsequentCount );
|
||||||
// also make sure it was cleaned up from the internal ThreadLocal...
|
// also make sure it was cleaned up from the internal ThreadLocal...
|
||||||
assertFalse( "session still bound to internal ThreadLocal", TestableThreadLocalContext.hasBind() );
|
assertFalse( "session still bound to internal ThreadLocal", TestableThreadLocalContext.hasBind() );
|
||||||
|
|
|
@ -159,7 +159,7 @@ public class MultiRepresentationTest extends BaseCoreFunctionalTestCase {
|
||||||
private Long stockId;
|
private Long stockId;
|
||||||
|
|
||||||
private void create() {
|
private void create() {
|
||||||
Session session = getSessions().openSession();
|
Session session = sessionFactory().openSession();
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
Stock stock = new Stock();
|
Stock stock = new Stock();
|
||||||
stock.setTradeSymbol( "JBOSS" );
|
stock.setTradeSymbol( "JBOSS" );
|
||||||
|
@ -180,7 +180,7 @@ public class MultiRepresentationTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void destroy() {
|
private void destroy() {
|
||||||
Session session = getSessions().openSession();
|
Session session = sessionFactory().openSession();
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
Iterator stocks = session.createQuery( "from Stock" ).list().iterator();
|
Iterator stocks = session.createQuery( "from Stock" ).list().iterator();
|
||||||
while ( stocks.hasNext() ) {
|
while ( stocks.hasNext() ) {
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class CallbackTest extends BaseCoreFunctionalTestCase {
|
||||||
assertEquals( "observer not notified of creation", 1, observer.creationCount );
|
assertEquals( "observer not notified of creation", 1, observer.creationCount );
|
||||||
assertEquals( "listener not notified of creation", 1, listener.initCount );
|
assertEquals( "listener not notified of creation", 1, listener.initCount );
|
||||||
|
|
||||||
sfi().close();
|
sessionFactory().close();
|
||||||
|
|
||||||
assertEquals( "observer not notified of close", 1, observer.closedCount );
|
assertEquals( "observer not notified of close", 1, observer.closedCount );
|
||||||
assertEquals( "listener not notified of close", 1, listener.destoryCount );
|
assertEquals( "listener not notified of close", 1, listener.destoryCount );
|
||||||
|
|
|
@ -120,7 +120,7 @@ public class ExtendsTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
cfg.buildSessionFactory( serviceRegistry );
|
cfg.buildSessionFactory( serviceRegistry );
|
||||||
|
|
||||||
fail( "Should not be able to build sessionfactory without a Person" );
|
fail( "Should not be able to build sessionFactory without a Person" );
|
||||||
}
|
}
|
||||||
catch ( HibernateException e ) {
|
catch ( HibernateException e ) {
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
session.close();
|
session.close();
|
||||||
|
|
||||||
sfi().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
|
|
||||||
testCode.perform(
|
testCode.perform(
|
||||||
new TestData() {
|
new TestData() {
|
||||||
|
@ -134,13 +134,13 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
|
||||||
Session session = openSession();
|
Session session = openSession();
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
CourseOffering section = ( CourseOffering ) session.get( CourseOffering.class, data.getSectionId() );
|
CourseOffering section = ( CourseOffering ) session.get( CourseOffering.class, data.getSectionId() );
|
||||||
assertEquals( 1, sfi().getStatistics().getEntityLoadCount() );
|
assertEquals( 1, sessionFactory().getStatistics().getEntityLoadCount() );
|
||||||
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() );
|
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||||
assertFalse( Hibernate.isInitialized( section.getCourse() ) );
|
assertFalse( Hibernate.isInitialized( section.getCourse() ) );
|
||||||
assertFalse( Hibernate.isInitialized( section.getEnrollments() ) );
|
assertFalse( Hibernate.isInitialized( section.getEnrollments() ) );
|
||||||
assertFalse( Hibernate.isInitialized( section.getCourse().getCode().getDepartment() ) );
|
assertFalse( Hibernate.isInitialized( section.getCourse().getCode().getDepartment() ) );
|
||||||
assertTrue( Hibernate.isInitialized( section.getCourse() ) );
|
assertTrue( Hibernate.isInitialized( section.getCourse() ) );
|
||||||
assertEquals( 1, sfi().getStatistics().getEntityFetchCount() );
|
assertEquals( 1, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
session.close();
|
session.close();
|
||||||
}
|
}
|
||||||
|
@ -156,13 +156,13 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
|
||||||
Session session = openSession();
|
Session session = openSession();
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
CourseOffering section = ( CourseOffering ) session.createCriteria( CourseOffering.class ).uniqueResult();
|
CourseOffering section = ( CourseOffering ) session.createCriteria( CourseOffering.class ).uniqueResult();
|
||||||
assertEquals( 1, sfi().getStatistics().getEntityLoadCount() );
|
assertEquals( 1, sessionFactory().getStatistics().getEntityLoadCount() );
|
||||||
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() );
|
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||||
assertFalse( Hibernate.isInitialized( section.getCourse() ) );
|
assertFalse( Hibernate.isInitialized( section.getCourse() ) );
|
||||||
assertFalse( Hibernate.isInitialized( section.getEnrollments() ) );
|
assertFalse( Hibernate.isInitialized( section.getEnrollments() ) );
|
||||||
assertFalse( Hibernate.isInitialized( section.getCourse().getCode().getDepartment() ) );
|
assertFalse( Hibernate.isInitialized( section.getCourse().getCode().getDepartment() ) );
|
||||||
assertTrue( Hibernate.isInitialized( section.getCourse() ) );
|
assertTrue( Hibernate.isInitialized( section.getCourse() ) );
|
||||||
assertEquals( 1, sfi().getStatistics().getEntityFetchCount() );
|
assertEquals( 1, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
session.close();
|
session.close();
|
||||||
}
|
}
|
||||||
|
@ -172,9 +172,9 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicFetchProfileOperation() {
|
public void testBasicFetchProfileOperation() {
|
||||||
assertTrue( "fetch profile not parsed properly", sfi().containsFetchProfileDefinition( "enrollment.details" ) );
|
assertTrue( "fetch profile not parsed properly", sessionFactory().containsFetchProfileDefinition( "enrollment.details" ) );
|
||||||
assertTrue( "fetch profile not parsed properly", sfi().containsFetchProfileDefinition( "offering.details" ) );
|
assertTrue( "fetch profile not parsed properly", sessionFactory().containsFetchProfileDefinition( "offering.details" ) );
|
||||||
assertTrue( "fetch profile not parsed properly", sfi().containsFetchProfileDefinition( "course.details" ) );
|
assertTrue( "fetch profile not parsed properly", sessionFactory().containsFetchProfileDefinition( "course.details" ) );
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
SessionImplementor si = ( SessionImplementor ) s;
|
SessionImplementor si = ( SessionImplementor ) s;
|
||||||
s.enableFetchProfile( "enrollment.details" );
|
s.enableFetchProfile( "enrollment.details" );
|
||||||
|
@ -199,11 +199,11 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
session.enableFetchProfile( "enrollment.details" );
|
session.enableFetchProfile( "enrollment.details" );
|
||||||
Enrollment enrollment = ( Enrollment ) session.get( Enrollment.class, data.getEnrollmentId() );
|
Enrollment enrollment = ( Enrollment ) session.get( Enrollment.class, data.getEnrollmentId() );
|
||||||
assertEquals( 3, sfi().getStatistics().getEntityLoadCount() ); // enrollment + (section + student)
|
assertEquals( 3, sessionFactory().getStatistics().getEntityLoadCount() ); // enrollment + (section + student)
|
||||||
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() );
|
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||||
assertTrue( Hibernate.isInitialized( enrollment.getOffering() ) );
|
assertTrue( Hibernate.isInitialized( enrollment.getOffering() ) );
|
||||||
assertTrue( Hibernate.isInitialized( enrollment.getStudent() ) );
|
assertTrue( Hibernate.isInitialized( enrollment.getStudent() ) );
|
||||||
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() );
|
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
session.close();
|
session.close();
|
||||||
}
|
}
|
||||||
|
@ -220,11 +220,11 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
session.enableFetchProfile( "enrollment.details" );
|
session.enableFetchProfile( "enrollment.details" );
|
||||||
Enrollment enrollment = ( Enrollment ) session.createCriteria( Enrollment.class ).uniqueResult();
|
Enrollment enrollment = ( Enrollment ) session.createCriteria( Enrollment.class ).uniqueResult();
|
||||||
assertEquals( 3, sfi().getStatistics().getEntityLoadCount() ); // enrollment + (section + student)
|
assertEquals( 3, sessionFactory().getStatistics().getEntityLoadCount() ); // enrollment + (section + student)
|
||||||
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() );
|
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||||
assertTrue( Hibernate.isInitialized( enrollment.getOffering() ) );
|
assertTrue( Hibernate.isInitialized( enrollment.getOffering() ) );
|
||||||
assertTrue( Hibernate.isInitialized( enrollment.getStudent() ) );
|
assertTrue( Hibernate.isInitialized( enrollment.getStudent() ) );
|
||||||
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() );
|
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
session.close();
|
session.close();
|
||||||
}
|
}
|
||||||
|
@ -241,8 +241,8 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
session.enableFetchProfile( "offering.details" );
|
session.enableFetchProfile( "offering.details" );
|
||||||
CourseOffering section = ( CourseOffering ) session.get( CourseOffering.class, data.getSectionId() );
|
CourseOffering section = ( CourseOffering ) session.get( CourseOffering.class, data.getSectionId() );
|
||||||
assertEquals( 3, sfi().getStatistics().getEntityLoadCount() ); // section + (enrollments + course)
|
assertEquals( 3, sessionFactory().getStatistics().getEntityLoadCount() ); // section + (enrollments + course)
|
||||||
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() );
|
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||||
assertTrue( Hibernate.isInitialized( section.getEnrollments() ) );
|
assertTrue( Hibernate.isInitialized( section.getEnrollments() ) );
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
session.close();
|
session.close();
|
||||||
|
@ -264,8 +264,8 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
|
||||||
session.enableFetchProfile( "offering.details" );
|
session.enableFetchProfile( "offering.details" );
|
||||||
session.enableFetchProfile( "enrollment.details" );
|
session.enableFetchProfile( "enrollment.details" );
|
||||||
CourseOffering section = ( CourseOffering ) session.get( CourseOffering.class, data.getSectionId() );
|
CourseOffering section = ( CourseOffering ) session.get( CourseOffering.class, data.getSectionId() );
|
||||||
assertEquals( 4, sfi().getStatistics().getEntityLoadCount() ); // section + (course + enrollments + (student))
|
assertEquals( 4, sessionFactory().getStatistics().getEntityLoadCount() ); // section + (course + enrollments + (student))
|
||||||
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() );
|
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||||
assertTrue( Hibernate.isInitialized( section.getEnrollments() ) );
|
assertTrue( Hibernate.isInitialized( section.getEnrollments() ) );
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
session.close();
|
session.close();
|
||||||
|
@ -283,8 +283,8 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
session.enableFetchProfile( "course.details" );
|
session.enableFetchProfile( "course.details" );
|
||||||
Course course = ( Course ) session.get( Course.class, data.getCourseId() );
|
Course course = ( Course ) session.get( Course.class, data.getCourseId() );
|
||||||
assertEquals( 2, sfi().getStatistics().getEntityLoadCount() ); // course + department
|
assertEquals( 2, sessionFactory().getStatistics().getEntityLoadCount() ); // course + department
|
||||||
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() );
|
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||||
assertTrue( Hibernate.isInitialized( course.getCode().getDepartment() ) );
|
assertTrue( Hibernate.isInitialized( course.getCode().getDepartment() ) );
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
session.close();
|
session.close();
|
||||||
|
@ -310,8 +310,8 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
|
||||||
List sections = session.createQuery( "from CourseOffering" ).list();
|
List sections = session.createQuery( "from CourseOffering" ).list();
|
||||||
int sectionCount = sections.size();
|
int sectionCount = sections.size();
|
||||||
assertEquals( "unexpected CourseOffering count", 1, sectionCount );
|
assertEquals( "unexpected CourseOffering count", 1, sectionCount );
|
||||||
assertEquals( 1, sfi().getStatistics().getEntityLoadCount() );
|
assertEquals( 1, sessionFactory().getStatistics().getEntityLoadCount() );
|
||||||
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() );
|
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
session.close();
|
session.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class DynamicFilterTest extends BaseCoreFunctionalTestCase {
|
||||||
CollectionPersister persister = sessionFactory().getCollectionPersister( Salesperson.class.getName() + ".orders" );
|
CollectionPersister persister = sessionFactory().getCollectionPersister( Salesperson.class.getName() + ".orders" );
|
||||||
assertTrue( "No cache for collection", persister.hasCache() );
|
assertTrue( "No cache for collection", persister.hasCache() );
|
||||||
CollectionCacheEntry cachedData = ( CollectionCacheEntry ) persister.getCacheAccessStrategy()
|
CollectionCacheEntry cachedData = ( CollectionCacheEntry ) persister.getCacheAccessStrategy()
|
||||||
.get( new CacheKey( testData.steveId, persister.getKeyType(), persister.getRole(), EntityMode.POJO, sfi() ), ts );
|
.get( new CacheKey( testData.steveId, persister.getKeyType(), persister.getRole(), EntityMode.POJO, sessionFactory() ), ts );
|
||||||
assertNotNull( "collection was not in cache", cachedData );
|
assertNotNull( "collection was not in cache", cachedData );
|
||||||
|
|
||||||
session.close();
|
session.close();
|
||||||
|
@ -125,7 +125,7 @@ public class DynamicFilterTest extends BaseCoreFunctionalTestCase {
|
||||||
assertEquals( "Filtered-collection not bypassing 2L-cache", 1, sp.getOrders().size() );
|
assertEquals( "Filtered-collection not bypassing 2L-cache", 1, sp.getOrders().size() );
|
||||||
|
|
||||||
CollectionCacheEntry cachedData2 = ( CollectionCacheEntry ) persister.getCacheAccessStrategy()
|
CollectionCacheEntry cachedData2 = ( CollectionCacheEntry ) persister.getCacheAccessStrategy()
|
||||||
.get( new CacheKey( testData.steveId, persister.getKeyType(), persister.getRole(), EntityMode.POJO, sfi() ), ts );
|
.get( new CacheKey( testData.steveId, persister.getKeyType(), persister.getRole(), EntityMode.POJO, sessionFactory() ), ts );
|
||||||
assertNotNull( "collection no longer in cache!", cachedData2 );
|
assertNotNull( "collection no longer in cache!", cachedData2 );
|
||||||
assertSame( "Different cache values!", cachedData, cachedData2 );
|
assertSame( "Different cache values!", cachedData, cachedData2 );
|
||||||
|
|
||||||
|
|
|
@ -52,15 +52,15 @@ public class IdentityGeneratedKeysTest extends BaseCoreFunctionalTestCase {
|
||||||
assertEquals( id, myEntity1.getId() );
|
assertEquals( id, myEntity1.getId() );
|
||||||
|
|
||||||
// next test persist() which should cause a delayed insert...
|
// next test persist() which should cause a delayed insert...
|
||||||
long initialInsertCount = sfi().getStatistics().getEntityInsertCount();
|
long initialInsertCount = sessionFactory().getStatistics().getEntityInsertCount();
|
||||||
MyEntity myEntity2 = new MyEntity( "test-persist");
|
MyEntity myEntity2 = new MyEntity( "test-persist");
|
||||||
s.persist( myEntity2 );
|
s.persist( myEntity2 );
|
||||||
assertEquals( "persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount() );
|
assertEquals( "persist on identity column not delayed", initialInsertCount, sessionFactory().getStatistics().getEntityInsertCount() );
|
||||||
assertNull( myEntity2.getId() );
|
assertNull( myEntity2.getId() );
|
||||||
|
|
||||||
// an explicit flush should cause execution of the delayed insertion
|
// an explicit flush should cause execution of the delayed insertion
|
||||||
s.flush();
|
s.flush();
|
||||||
assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 1, sfi().getStatistics().getEntityInsertCount() );
|
assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 1, sessionFactory().getStatistics().getEntityInsertCount() );
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
|
@ -74,15 +74,15 @@ public class IdentityGeneratedKeysTest extends BaseCoreFunctionalTestCase {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings( {"unchecked"})
|
@SuppressWarnings( {"unchecked"})
|
||||||
public void testPersistOutsideTransactionCascadedToNonInverseCollection() {
|
public void testPersistOutsideTransactionCascadedToNonInverseCollection() {
|
||||||
long initialInsertCount = sfi().getStatistics().getEntityInsertCount();
|
long initialInsertCount = sessionFactory().getStatistics().getEntityInsertCount();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
MyEntity myEntity = new MyEntity( "test-persist");
|
MyEntity myEntity = new MyEntity( "test-persist");
|
||||||
myEntity.getNonInverseChildren().add( new MyChild( "test-child-persist-non-inverse" ) );
|
myEntity.getNonInverseChildren().add( new MyChild( "test-child-persist-non-inverse" ) );
|
||||||
s.persist( myEntity );
|
s.persist( myEntity );
|
||||||
assertEquals( "persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount() );
|
assertEquals( "persist on identity column not delayed", initialInsertCount, sessionFactory().getStatistics().getEntityInsertCount() );
|
||||||
assertNull( myEntity.getId() );
|
assertNull( myEntity.getId() );
|
||||||
s.flush();
|
s.flush();
|
||||||
assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sfi().getStatistics().getEntityInsertCount() );
|
assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sessionFactory().getStatistics().getEntityInsertCount() );
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
|
@ -96,17 +96,17 @@ public class IdentityGeneratedKeysTest extends BaseCoreFunctionalTestCase {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings( {"unchecked"})
|
@SuppressWarnings( {"unchecked"})
|
||||||
public void testPersistOutsideTransactionCascadedToInverseCollection() {
|
public void testPersistOutsideTransactionCascadedToInverseCollection() {
|
||||||
long initialInsertCount = sfi().getStatistics().getEntityInsertCount();
|
long initialInsertCount = sessionFactory().getStatistics().getEntityInsertCount();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
MyEntity myEntity2 = new MyEntity( "test-persist-2");
|
MyEntity myEntity2 = new MyEntity( "test-persist-2");
|
||||||
MyChild child = new MyChild( "test-child-persist-inverse" );
|
MyChild child = new MyChild( "test-child-persist-inverse" );
|
||||||
myEntity2.getInverseChildren().add( child );
|
myEntity2.getInverseChildren().add( child );
|
||||||
child.setInverseParent( myEntity2 );
|
child.setInverseParent( myEntity2 );
|
||||||
s.persist( myEntity2 );
|
s.persist( myEntity2 );
|
||||||
assertEquals( "persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount() );
|
assertEquals( "persist on identity column not delayed", initialInsertCount, sessionFactory().getStatistics().getEntityInsertCount() );
|
||||||
assertNull( myEntity2.getId() );
|
assertNull( myEntity2.getId() );
|
||||||
s.flush();
|
s.flush();
|
||||||
assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sfi().getStatistics().getEntityInsertCount() );
|
assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sessionFactory().getStatistics().getEntityInsertCount() );
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
|
@ -119,15 +119,15 @@ public class IdentityGeneratedKeysTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistOutsideTransactionCascadedToManyToOne() {
|
public void testPersistOutsideTransactionCascadedToManyToOne() {
|
||||||
long initialInsertCount = sfi().getStatistics().getEntityInsertCount();
|
long initialInsertCount = sessionFactory().getStatistics().getEntityInsertCount();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
MyEntity myEntity = new MyEntity( "test-persist");
|
MyEntity myEntity = new MyEntity( "test-persist");
|
||||||
myEntity.setSibling( new MySibling( "test-persist-sibling-out" ) );
|
myEntity.setSibling( new MySibling( "test-persist-sibling-out" ) );
|
||||||
s.persist( myEntity );
|
s.persist( myEntity );
|
||||||
assertEquals( "persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount() );
|
assertEquals( "persist on identity column not delayed", initialInsertCount, sessionFactory().getStatistics().getEntityInsertCount() );
|
||||||
assertNull( myEntity.getId() );
|
assertNull( myEntity.getId() );
|
||||||
s.flush();
|
s.flush();
|
||||||
assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sfi().getStatistics().getEntityInsertCount() );
|
assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sessionFactory().getStatistics().getEntityInsertCount() );
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
|
@ -140,16 +140,16 @@ public class IdentityGeneratedKeysTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistOutsideTransactionCascadedFromManyToOne() {
|
public void testPersistOutsideTransactionCascadedFromManyToOne() {
|
||||||
long initialInsertCount = sfi().getStatistics().getEntityInsertCount();
|
long initialInsertCount = sessionFactory().getStatistics().getEntityInsertCount();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
MyEntity myEntity2 = new MyEntity( "test-persist-2");
|
MyEntity myEntity2 = new MyEntity( "test-persist-2");
|
||||||
MySibling sibling = new MySibling( "test-persist-sibling-in" );
|
MySibling sibling = new MySibling( "test-persist-sibling-in" );
|
||||||
sibling.setEntity( myEntity2 );
|
sibling.setEntity( myEntity2 );
|
||||||
s.persist( sibling );
|
s.persist( sibling );
|
||||||
assertEquals( "persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount() );
|
assertEquals( "persist on identity column not delayed", initialInsertCount, sessionFactory().getStatistics().getEntityInsertCount() );
|
||||||
assertNull( myEntity2.getId() );
|
assertNull( myEntity2.getId() );
|
||||||
s.flush();
|
s.flush();
|
||||||
assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sfi().getStatistics().getEntityInsertCount() );
|
assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sessionFactory().getStatistics().getEntityInsertCount() );
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
|
|
|
@ -2394,7 +2394,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
|
||||||
sr.close();
|
sr.close();
|
||||||
|
|
||||||
// caching...
|
// caching...
|
||||||
QueryStatistics stats = getSessions().getStatistics().getQueryStatistics( "select new Animal(an.description, an.bodyWeight) from Animal an" );
|
QueryStatistics stats = sessionFactory().getStatistics().getQueryStatistics( "select new Animal(an.description, an.bodyWeight) from Animal an" );
|
||||||
results = session.createQuery( "select new Animal(an.description, an.bodyWeight) from Animal an" )
|
results = session.createQuery( "select new Animal(an.description, an.bodyWeight) from Animal an" )
|
||||||
.setCacheable( true )
|
.setCacheable( true )
|
||||||
.list();
|
.list();
|
||||||
|
@ -2440,20 +2440,20 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
|
||||||
t.commit();
|
t.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
getSessions().getCache().evictQueryRegions();
|
sessionFactory().getCache().evictQueryRegions();
|
||||||
getSessions().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
t = s.beginTransaction();
|
t = s.beginTransaction();
|
||||||
List list = s.createQuery( "from Animal a left join fetch a.mother" ).setCacheable( true ).list();
|
List list = s.createQuery( "from Animal a left join fetch a.mother" ).setCacheable( true ).list();
|
||||||
assertEquals( 0, getSessions().getStatistics().getQueryCacheHitCount() );
|
assertEquals( 0, sessionFactory().getStatistics().getQueryCacheHitCount() );
|
||||||
assertEquals( 1, getSessions().getStatistics().getQueryCachePutCount() );
|
assertEquals( 1, sessionFactory().getStatistics().getQueryCachePutCount() );
|
||||||
list = s.createQuery( "select a from Animal a left join fetch a.mother" ).setCacheable( true ).list();
|
list = s.createQuery( "select a from Animal a left join fetch a.mother" ).setCacheable( true ).list();
|
||||||
assertEquals( 1, getSessions().getStatistics().getQueryCacheHitCount() );
|
assertEquals( 1, sessionFactory().getStatistics().getQueryCacheHitCount() );
|
||||||
assertEquals( 1, getSessions().getStatistics().getQueryCachePutCount() );
|
assertEquals( 1, sessionFactory().getStatistics().getQueryCachePutCount() );
|
||||||
list = s.createQuery( "select a, m from Animal a left join a.mother m" ).setCacheable( true ).list();
|
list = s.createQuery( "select a, m from Animal a left join a.mother m" ).setCacheable( true ).list();
|
||||||
assertEquals( 1, getSessions().getStatistics().getQueryCacheHitCount() );
|
assertEquals( 1, sessionFactory().getStatistics().getQueryCacheHitCount() );
|
||||||
assertEquals( 2, getSessions().getStatistics().getQueryCachePutCount() );
|
assertEquals( 2, sessionFactory().getStatistics().getQueryCachePutCount() );
|
||||||
s.createQuery( "delete from Animal" ).executeUpdate();
|
s.createQuery( "delete from Animal" ).executeUpdate();
|
||||||
t.commit();
|
t.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
@ -2477,8 +2477,8 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
|
||||||
a.addOffspring( offspring2 );
|
a.addOffspring( offspring2 );
|
||||||
offspring2.setMother( a );
|
offspring2.setMother( a );
|
||||||
|
|
||||||
getSessions().getCache().evictQueryRegions();
|
sessionFactory().getCache().evictQueryRegions();
|
||||||
getSessions().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
|
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Transaction t = s.beginTransaction();
|
Transaction t = s.beginTransaction();
|
||||||
|
@ -2492,14 +2492,14 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
|
||||||
s = openSession();
|
s = openSession();
|
||||||
t = s.beginTransaction();
|
t = s.beginTransaction();
|
||||||
List list = s.createQuery( "from Animal a left join fetch a.offspring" ).setCacheable( true ).list();
|
List list = s.createQuery( "from Animal a left join fetch a.offspring" ).setCacheable( true ).list();
|
||||||
assertEquals( 0, getSessions().getStatistics().getQueryCacheHitCount() );
|
assertEquals( 0, sessionFactory().getStatistics().getQueryCacheHitCount() );
|
||||||
assertEquals( 1, getSessions().getStatistics().getQueryCachePutCount() );
|
assertEquals( 1, sessionFactory().getStatistics().getQueryCachePutCount() );
|
||||||
list = s.createQuery( "select a from Animal a left join fetch a.offspring" ).setCacheable( true ).list();
|
list = s.createQuery( "select a from Animal a left join fetch a.offspring" ).setCacheable( true ).list();
|
||||||
assertEquals( 1, getSessions().getStatistics().getQueryCacheHitCount() );
|
assertEquals( 1, sessionFactory().getStatistics().getQueryCacheHitCount() );
|
||||||
assertEquals( 1, getSessions().getStatistics().getQueryCachePutCount() );
|
assertEquals( 1, sessionFactory().getStatistics().getQueryCachePutCount() );
|
||||||
list = s.createQuery( "select a, o from Animal a left join a.offspring o" ).setCacheable( true ).list();
|
list = s.createQuery( "select a, o from Animal a left join a.offspring o" ).setCacheable( true ).list();
|
||||||
assertEquals( 1, getSessions().getStatistics().getQueryCacheHitCount() );
|
assertEquals( 1, sessionFactory().getStatistics().getQueryCacheHitCount() );
|
||||||
assertEquals( 2, getSessions().getStatistics().getQueryCachePutCount() );
|
assertEquals( 2, sessionFactory().getStatistics().getQueryCachePutCount() );
|
||||||
s.createQuery( "delete from Animal" ).executeUpdate();
|
s.createQuery( "delete from Animal" ).executeUpdate();
|
||||||
t.commit();
|
t.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
|
@ -342,7 +342,7 @@ public class BulkManipulationTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean supportsBulkInsertIdGeneration(Class entityClass) {
|
protected boolean supportsBulkInsertIdGeneration(Class entityClass) {
|
||||||
EntityPersister persister = sfi().getEntityPersister( entityClass.getName() );
|
EntityPersister persister = sessionFactory().getEntityPersister( entityClass.getName() );
|
||||||
IdentifierGenerator generator = persister.getIdentifierGenerator();
|
IdentifierGenerator generator = persister.getIdentifierGenerator();
|
||||||
return HqlSqlWalker.supportsIdGenWithBulkInsertion( generator );
|
return HqlSqlWalker.supportsIdGenWithBulkInsertion( generator );
|
||||||
}
|
}
|
||||||
|
|
|
@ -262,11 +262,11 @@ public class EJBQLTest extends BaseCoreFunctionalTestCase {
|
||||||
private void assertEjbqlEqualsHql(String ejbql, String hql) {
|
private void assertEjbqlEqualsHql(String ejbql, String hql) {
|
||||||
QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
|
QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
|
||||||
|
|
||||||
QueryTranslator queryTranslator = ast.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, sfi() );
|
QueryTranslator queryTranslator = ast.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, sessionFactory() );
|
||||||
queryTranslator.compile( Collections.EMPTY_MAP, true );
|
queryTranslator.compile( Collections.EMPTY_MAP, true );
|
||||||
String hqlSql = queryTranslator.getSQLString();
|
String hqlSql = queryTranslator.getSQLString();
|
||||||
|
|
||||||
queryTranslator = ast.createQueryTranslator( ejbql, ejbql, Collections.EMPTY_MAP, sfi() );
|
queryTranslator = ast.createQueryTranslator( ejbql, ejbql, Collections.EMPTY_MAP, sessionFactory() );
|
||||||
queryTranslator.compile( Collections.EMPTY_MAP, true );
|
queryTranslator.compile( Collections.EMPTY_MAP, true );
|
||||||
String ejbqlSql = queryTranslator.getSQLString();
|
String ejbqlSql = queryTranslator.getSQLString();
|
||||||
|
|
||||||
|
@ -275,7 +275,7 @@ public class EJBQLTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
private QueryTranslatorImpl compile(String input) {
|
private QueryTranslatorImpl compile(String input) {
|
||||||
QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
|
QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
|
||||||
QueryTranslator queryTranslator = ast.createQueryTranslator( input, input, Collections.EMPTY_MAP, sfi() );
|
QueryTranslator queryTranslator = ast.createQueryTranslator( input, input, Collections.EMPTY_MAP, sessionFactory() );
|
||||||
queryTranslator.compile( Collections.EMPTY_MAP, true );
|
queryTranslator.compile( Collections.EMPTY_MAP, true );
|
||||||
|
|
||||||
return ( QueryTranslatorImpl ) queryTranslator;
|
return ( QueryTranslatorImpl ) queryTranslator;
|
||||||
|
@ -305,7 +305,7 @@ public class EJBQLTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
private String toSql(String hql) {
|
private String toSql(String hql) {
|
||||||
QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
|
QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
|
||||||
QueryTranslator queryTranslator = ast.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, sfi() );
|
QueryTranslator queryTranslator = ast.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, sessionFactory() );
|
||||||
queryTranslator.compile( Collections.EMPTY_MAP, true );
|
queryTranslator.compile( Collections.EMPTY_MAP, true );
|
||||||
return queryTranslator.getSQLString();
|
return queryTranslator.getSQLString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,6 @@ import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
|
||||||
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
@ -49,7 +48,7 @@ public class BasicForcedTableSequenceTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNormalBoundary() {
|
public void testNormalBoundary() {
|
||||||
EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() );
|
EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"sequence style generator was not used",
|
"sequence style generator was not used",
|
||||||
SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() )
|
SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() )
|
||||||
|
|
|
@ -34,7 +34,6 @@ import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
|
||||||
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
@ -50,7 +49,7 @@ public class HiLoForcedTableSequenceTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNormalBoundary() {
|
public void testNormalBoundary() {
|
||||||
EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() );
|
EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"sequence style generator was not used",
|
"sequence style generator was not used",
|
||||||
SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() )
|
SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() )
|
||||||
|
|
|
@ -34,7 +34,6 @@ import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
|
||||||
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
@ -48,7 +47,7 @@ public class PooledForcedTableSequenceTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNormalBoundary() {
|
public void testNormalBoundary() {
|
||||||
EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() );
|
EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"sequence style generator was not used",
|
"sequence style generator was not used",
|
||||||
SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() )
|
SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() )
|
||||||
|
|
|
@ -34,7 +34,6 @@ import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
|
||||||
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
|
||||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertClassAssignability;
|
import static org.hibernate.testing.junit4.ExtraAssertions.assertClassAssignability;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
@ -48,7 +47,7 @@ public class HiLoSequenceTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNormalBoundary() {
|
public void testNormalBoundary() {
|
||||||
EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() );
|
EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
|
||||||
assertClassAssignability( SequenceStyleGenerator.class, persister.getIdentifierGenerator().getClass() );
|
assertClassAssignability( SequenceStyleGenerator.class, persister.getIdentifierGenerator().getClass() );
|
||||||
SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator();
|
SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator();
|
||||||
assertClassAssignability( OptimizerFactory.HiLoOptimizer.class, generator.getOptimizer().getClass() );
|
assertClassAssignability( OptimizerFactory.HiLoOptimizer.class, generator.getOptimizer().getClass() );
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.immutable.entitywithmutablecollection;
|
package org.hibernate.test.immutable.entitywithmutablecollection;
|
||||||
import java.util.Iterator;
|
|
||||||
import org.hibernate.QueryException;
|
import org.hibernate.QueryException;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.StaleObjectStateException;
|
import org.hibernate.StaleObjectStateException;
|
||||||
|
@ -68,23 +67,23 @@ public abstract class AbstractEntityWithOneToManyTest extends BaseCoreFunctional
|
||||||
|
|
||||||
protected void prepareTest() throws Exception {
|
protected void prepareTest() throws Exception {
|
||||||
super.prepareTest();
|
super.prepareTest();
|
||||||
isContractPartiesInverse = ( ( SessionFactoryImpl ) getSessions() ).getCollectionPersister( Contract.class.getName() + ".parties" ).isInverse();
|
isContractPartiesInverse = ( ( SessionFactoryImpl ) sessionFactory() ).getCollectionPersister( Contract.class.getName() + ".parties" ).isInverse();
|
||||||
try {
|
try {
|
||||||
( ( SessionFactoryImpl ) getSessions() ).getEntityPersister( Party.class.getName() ).getPropertyType( "contract" );
|
( ( SessionFactoryImpl ) sessionFactory() ).getEntityPersister( Party.class.getName() ).getPropertyType( "contract" );
|
||||||
isContractPartiesBidirectional = true;
|
isContractPartiesBidirectional = true;
|
||||||
}
|
}
|
||||||
catch ( QueryException ex) {
|
catch ( QueryException ex) {
|
||||||
isContractPartiesBidirectional = false;
|
isContractPartiesBidirectional = false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
( ( SessionFactoryImpl ) getSessions() ).getEntityPersister( ContractVariation.class.getName() ).getPropertyType( "contract" );
|
( ( SessionFactoryImpl ) sessionFactory() ).getEntityPersister( ContractVariation.class.getName() ).getPropertyType( "contract" );
|
||||||
isContractVariationsBidirectional = true;
|
isContractVariationsBidirectional = true;
|
||||||
}
|
}
|
||||||
catch ( QueryException ex) {
|
catch ( QueryException ex) {
|
||||||
isContractVariationsBidirectional = false;
|
isContractVariationsBidirectional = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
isContractVersioned = ( ( SessionFactoryImpl ) getSessions() ).getEntityPersister( Contract.class.getName() ).isVersioned();
|
isContractVersioned = ( ( SessionFactoryImpl ) sessionFactory() ).getEntityPersister( Contract.class.getName() ).isVersioned();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1201,21 +1200,21 @@ public abstract class AbstractEntityWithOneToManyTest extends BaseCoreFunctional
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void clearCounts() {
|
protected void clearCounts() {
|
||||||
getSessions().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertInsertCount(int expected) {
|
protected void assertInsertCount(int expected) {
|
||||||
int inserts = ( int ) getSessions().getStatistics().getEntityInsertCount();
|
int inserts = ( int ) sessionFactory().getStatistics().getEntityInsertCount();
|
||||||
assertEquals( "unexpected insert count", expected, inserts );
|
assertEquals( "unexpected insert count", expected, inserts );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertUpdateCount(int expected) {
|
protected void assertUpdateCount(int expected) {
|
||||||
int updates = ( int ) getSessions().getStatistics().getEntityUpdateCount();
|
int updates = ( int ) sessionFactory().getStatistics().getEntityUpdateCount();
|
||||||
assertEquals( "unexpected update counts", expected, updates );
|
assertEquals( "unexpected update counts", expected, updates );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertDeleteCount(int expected) {
|
protected void assertDeleteCount(int expected) {
|
||||||
int deletes = ( int ) getSessions().getStatistics().getEntityDeleteCount();
|
int deletes = ( int ) sessionFactory().getStatistics().getEntityDeleteCount();
|
||||||
assertEquals( "unexpected delete counts", expected, deletes );
|
assertEquals( "unexpected delete counts", expected, deletes );
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -24,6 +24,7 @@
|
||||||
package org.hibernate.test.instrument.runtime;
|
package org.hibernate.test.instrument.runtime;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
|
@ -32,34 +33,44 @@ import org.hibernate.bytecode.InstrumentedClassLoader;
|
||||||
import org.hibernate.bytecode.util.BasicClassFilter;
|
import org.hibernate.bytecode.util.BasicClassFilter;
|
||||||
import org.hibernate.bytecode.util.FieldFilter;
|
import org.hibernate.bytecode.util.FieldFilter;
|
||||||
import org.hibernate.testing.junit4.BaseClassLoaderIsolatedTestCase;
|
import org.hibernate.testing.junit4.BaseClassLoaderIsolatedTestCase;
|
||||||
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
|
import org.hibernate.testing.junit4.ClassLoadingIsolater;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractTransformingClassLoaderInstrumentTestCase extends BaseClassLoaderIsolatedTestCase {
|
public abstract class AbstractTransformingClassLoaderInstrumentTestCase extends BaseUnitTestCase {
|
||||||
|
|
||||||
protected ClassLoader buildIsolatedClassLoader(ClassLoader parent) {
|
@Rule
|
||||||
BytecodeProvider provider = buildBytecodeProvider();
|
public ClassLoadingIsolater isolater = new ClassLoadingIsolater(
|
||||||
return new InstrumentedClassLoader(
|
new ClassLoadingIsolater.IsolatedClassLoaderProvider() {
|
||||||
parent,
|
final BytecodeProvider provider = buildBytecodeProvider();
|
||||||
provider.getTransformer(
|
|
||||||
new BasicClassFilter( new String[] { "org.hibernate.test.instrument" }, null ),
|
|
||||||
new FieldFilter() {
|
|
||||||
public boolean shouldInstrumentField(String className, String fieldName) {
|
|
||||||
return className.startsWith( "org.hibernate.test.instrument.domain" );
|
|
||||||
}
|
|
||||||
public boolean shouldTransformFieldAccess(String transformingClassName, String fieldOwnerClassName, String fieldName) {
|
|
||||||
return fieldOwnerClassName.startsWith( "org.hibernate.test.instrument.domain" )
|
|
||||||
&& transformingClassName.equals( fieldOwnerClassName );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
@Override
|
||||||
|
public ClassLoader buildIsolatedClassLoader() {
|
||||||
|
return new InstrumentedClassLoader(
|
||||||
|
Thread.currentThread().getContextClassLoader(),
|
||||||
|
provider.getTransformer(
|
||||||
|
new BasicClassFilter( new String[] { "org.hibernate.test.instrument" }, null ),
|
||||||
|
new FieldFilter() {
|
||||||
|
public boolean shouldInstrumentField(String className, String fieldName) {
|
||||||
|
return className.startsWith( "org.hibernate.test.instrument.domain" );
|
||||||
|
}
|
||||||
|
public boolean shouldTransformFieldAccess(String transformingClassName, String fieldOwnerClassName, String fieldName) {
|
||||||
|
return fieldOwnerClassName.startsWith( "org.hibernate.test.instrument.domain" )
|
||||||
|
&& transformingClassName.equals( fieldOwnerClassName );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected void releaseIsolatedClassLoader(ClassLoader isolatedLoader) {
|
@Override
|
||||||
}
|
public void releaseIsolatedClassLoader(ClassLoader isolatedClassLoader) {
|
||||||
|
// nothing to do
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
protected abstract BytecodeProvider buildBytecodeProvider();
|
protected abstract BytecodeProvider buildBytecodeProvider();
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class IterateTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIterate() throws Exception {
|
public void testIterate() throws Exception {
|
||||||
getSessions().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Transaction t = s.beginTransaction();
|
Transaction t = s.beginTransaction();
|
||||||
Item i1 = new Item("foo");
|
Item i1 = new Item("foo");
|
||||||
|
@ -86,12 +86,12 @@ public class IterateTest extends BaseCoreFunctionalTestCase {
|
||||||
s.delete(i2);
|
s.delete(i2);
|
||||||
t.commit();
|
t.commit();
|
||||||
s.close();
|
s.close();
|
||||||
assertEquals( getSessions().getStatistics().getEntityFetchCount(), 2 );
|
assertEquals( sessionFactory().getStatistics().getEntityFetchCount(), 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testScroll() throws Exception {
|
public void testScroll() throws Exception {
|
||||||
getSessions().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Transaction t = s.beginTransaction();
|
Transaction t = s.beginTransaction();
|
||||||
Item i1 = new Item("foo");
|
Item i1 = new Item("foo");
|
||||||
|
@ -117,7 +117,7 @@ public class IterateTest extends BaseCoreFunctionalTestCase {
|
||||||
s.delete(i2);
|
s.delete(i2);
|
||||||
t.commit();
|
t.commit();
|
||||||
s.close();
|
s.close();
|
||||||
assertEquals( getSessions().getStatistics().getEntityFetchCount(), 0 );
|
assertEquals( sessionFactory().getStatistics().getEntityFetchCount(), 0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ public class LazyKeyManyToOneTest extends BaseCoreFunctionalTestCase {
|
||||||
cust.getOrders().add( order );
|
cust.getOrders().add( order );
|
||||||
s.save( cust );
|
s.save( cust );
|
||||||
s.flush();
|
s.flush();
|
||||||
assertEquals( 2, sfi().getStatistics().getEntityInsertCount() );
|
assertEquals( 2, sessionFactory().getStatistics().getEntityInsertCount() );
|
||||||
s.delete( cust );
|
s.delete( cust );
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class KeyManyToOneTest extends BaseCoreFunctionalTestCase {
|
||||||
cust.getOrders().add( order );
|
cust.getOrders().add( order );
|
||||||
s.save( cust );
|
s.save( cust );
|
||||||
s.flush();
|
s.flush();
|
||||||
assertEquals( 2, sfi().getStatistics().getEntityInsertCount() );
|
assertEquals( 2, sessionFactory().getStatistics().getEntityInsertCount() );
|
||||||
s.delete( cust );
|
s.delete( cust );
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
|
@ -68,21 +68,21 @@ public class InstrumentCacheTest extends BaseCoreFunctionalTestCase {
|
||||||
Session s;
|
Session s;
|
||||||
Transaction tx;
|
Transaction tx;
|
||||||
|
|
||||||
s = getSessions().openSession();
|
s = sessionFactory().openSession();
|
||||||
tx = s.beginTransaction();
|
tx = s.beginTransaction();
|
||||||
s.persist( new Document("HiA", "Hibernate book", "Hibernate is....") );
|
s.persist( new Document("HiA", "Hibernate book", "Hibernate is....") );
|
||||||
tx.commit();
|
tx.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
s = getSessions().openSession();
|
s = sessionFactory().openSession();
|
||||||
tx = s.beginTransaction();
|
tx = s.beginTransaction();
|
||||||
s.createQuery("from Document fetch all properties").uniqueResult();
|
s.createQuery("from Document fetch all properties").uniqueResult();
|
||||||
tx.commit();
|
tx.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
getSessions().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
|
|
||||||
s = getSessions().openSession();
|
s = sessionFactory().openSession();
|
||||||
tx = s.beginTransaction();
|
tx = s.beginTransaction();
|
||||||
Document d = (Document) s.createCriteria(Document.class).uniqueResult();
|
Document d = (Document) s.createCriteria(Document.class).uniqueResult();
|
||||||
assertFalse( Hibernate.isPropertyInitialized(d, "text") );
|
assertFalse( Hibernate.isPropertyInitialized(d, "text") );
|
||||||
|
@ -93,9 +93,9 @@ public class InstrumentCacheTest extends BaseCoreFunctionalTestCase {
|
||||||
tx.commit();
|
tx.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
assertEquals( 2, getSessions().getStatistics().getPrepareStatementCount() );
|
assertEquals( 2, sessionFactory().getStatistics().getPrepareStatementCount() );
|
||||||
|
|
||||||
s = getSessions().openSession();
|
s = sessionFactory().openSession();
|
||||||
tx = s.beginTransaction();
|
tx = s.beginTransaction();
|
||||||
d = (Document) s.get(Document.class, d.getId());
|
d = (Document) s.get(Document.class, d.getId());
|
||||||
assertFalse( Hibernate.isPropertyInitialized(d, "text") );
|
assertFalse( Hibernate.isPropertyInitialized(d, "text") );
|
||||||
|
@ -109,21 +109,21 @@ public class InstrumentCacheTest extends BaseCoreFunctionalTestCase {
|
||||||
Session s;
|
Session s;
|
||||||
Transaction tx;
|
Transaction tx;
|
||||||
|
|
||||||
s = getSessions().openSession();
|
s = sessionFactory().openSession();
|
||||||
tx = s.beginTransaction();
|
tx = s.beginTransaction();
|
||||||
s.persist( new Document("HiA", "Hibernate book", "Hibernate is....") );
|
s.persist( new Document("HiA", "Hibernate book", "Hibernate is....") );
|
||||||
tx.commit();
|
tx.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
s = getSessions().openSession();
|
s = sessionFactory().openSession();
|
||||||
tx = s.beginTransaction();
|
tx = s.beginTransaction();
|
||||||
s.createQuery("from Document fetch all properties").uniqueResult();
|
s.createQuery("from Document fetch all properties").uniqueResult();
|
||||||
tx.commit();
|
tx.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
getSessions().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
|
|
||||||
s = getSessions().openSession();
|
s = sessionFactory().openSession();
|
||||||
tx = s.beginTransaction();
|
tx = s.beginTransaction();
|
||||||
Document d = (Document) s.createCriteria(Document.class).uniqueResult();
|
Document d = (Document) s.createCriteria(Document.class).uniqueResult();
|
||||||
assertFalse( Hibernate.isPropertyInitialized(d, "text") );
|
assertFalse( Hibernate.isPropertyInitialized(d, "text") );
|
||||||
|
@ -134,9 +134,9 @@ public class InstrumentCacheTest extends BaseCoreFunctionalTestCase {
|
||||||
tx.commit();
|
tx.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
assertEquals( 1, getSessions().getStatistics().getPrepareStatementCount() );
|
assertEquals( 1, sessionFactory().getStatistics().getPrepareStatementCount() );
|
||||||
|
|
||||||
s = getSessions().openSession();
|
s = sessionFactory().openSession();
|
||||||
tx = s.beginTransaction();
|
tx = s.beginTransaction();
|
||||||
d = (Document) s.get(Document.class, d.getId());
|
d = (Document) s.get(Document.class, d.getId());
|
||||||
assertTrue( Hibernate.isPropertyInitialized(d, "text") );
|
assertTrue( Hibernate.isPropertyInitialized(d, "text") );
|
||||||
|
|
|
@ -57,14 +57,14 @@ public class ABCTest extends LegacyTestCase {
|
||||||
d = (D) s.get(D.class, did);
|
d = (D) s.get(D.class, did);
|
||||||
assertTrue(d.getReverse().getId().equals(did));
|
assertTrue(d.getReverse().getId().equals(did));
|
||||||
s.clear();
|
s.clear();
|
||||||
getSessions().evict(D.class);
|
sessionFactory().evict(D.class);
|
||||||
getSessions().evict(A.class);
|
sessionFactory().evict(A.class);
|
||||||
d = (D) s.get(D.class, did);
|
d = (D) s.get(D.class, did);
|
||||||
assertTrue(d.inverse.getId().equals(did));
|
assertTrue(d.inverse.getId().equals(did));
|
||||||
assertTrue(d.inverse.getName().equals("a"));
|
assertTrue(d.inverse.getName().equals("a"));
|
||||||
s.clear();
|
s.clear();
|
||||||
getSessions().evict(D.class);
|
sessionFactory().evict(D.class);
|
||||||
getSessions().evict(A.class);
|
sessionFactory().evict(A.class);
|
||||||
assertTrue( s.createQuery( "from D d join d.reverse r join d.inverse i where i = r" ).list().size()==1 );
|
assertTrue( s.createQuery( "from D d join d.reverse r join d.inverse i where i = r" ).list().size()==1 );
|
||||||
t.commit();
|
t.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
@ -72,7 +72,7 @@ public class ABCTest extends LegacyTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHigherLevelIndexDefinition() throws Throwable {
|
public void testHigherLevelIndexDefinition() throws Throwable {
|
||||||
String[] commands = getCfg().generateSchemaCreationScript( getDialect() );
|
String[] commands = configuration().generateSchemaCreationScript( getDialect() );
|
||||||
int max = commands.length;
|
int max = commands.length;
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (int indx = 0; indx < max; indx++) {
|
for (int indx = 0; indx < max; indx++) {
|
||||||
|
@ -105,7 +105,7 @@ public class ABCTest extends LegacyTestCase {
|
||||||
t.commit();
|
t.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
getSessions().evict(A.class);
|
sessionFactory().evict(A.class);
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
t = s.beginTransaction();
|
t = s.beginTransaction();
|
||||||
|
@ -120,7 +120,7 @@ public class ABCTest extends LegacyTestCase {
|
||||||
t.commit();
|
t.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
getSessions().evict(A.class);
|
sessionFactory().evict(A.class);
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
t = s.beginTransaction();
|
t = s.beginTransaction();
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class CustomSQLTest extends LegacyTestCase {
|
||||||
s.connection().commit();
|
s.connection().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
getSessions().evict(Role.class);
|
sessionFactory().evict(Role.class);
|
||||||
s = openSession();
|
s = openSession();
|
||||||
|
|
||||||
Role p2 = (Role) s.get(Role.class, new Long(p.getId()));
|
Role p2 = (Role) s.get(Role.class, new Long(p.getId()));
|
||||||
|
@ -178,7 +178,7 @@ public class CustomSQLTest extends LegacyTestCase {
|
||||||
s.connection().commit();
|
s.connection().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
getSessions().evict(Person.class);
|
sessionFactory().evict(Person.class);
|
||||||
s = openSession();
|
s = openSession();
|
||||||
|
|
||||||
Person p2 = (Person) s.get(Person.class, p.getId());
|
Person p2 = (Person) s.get(Person.class, p.getId());
|
||||||
|
|
|
@ -291,7 +291,7 @@ public class FooBarTest extends LegacyTestCase {
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
getSessions().evictCollection("org.hibernate.test.legacy.Baz.fooSet");
|
sessionFactory().evictCollection("org.hibernate.test.legacy.Baz.fooSet");
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
|
@ -340,7 +340,7 @@ public class FooBarTest extends LegacyTestCase {
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
getSessions().evictCollection("org.hibernate.test.legacy.Baz.fooSet");
|
sessionFactory().evictCollection("org.hibernate.test.legacy.Baz.fooSet");
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
|
@ -1518,7 +1518,7 @@ public class FooBarTest extends LegacyTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isOuterJoinFetchingDisabled() {
|
private boolean isOuterJoinFetchingDisabled() {
|
||||||
return new Integer(0).equals( ( (SessionFactoryImplementor) getSessions() ).getSettings().getMaximumFetchDepth() );
|
return new Integer(0).equals( ( (SessionFactoryImplementor) sessionFactory() ).getSettings().getMaximumFetchDepth() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1542,7 +1542,7 @@ public class FooBarTest extends LegacyTestCase {
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
getSessions().evict(Foo.class);
|
sessionFactory().evict(Foo.class);
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
|
@ -3202,7 +3202,7 @@ public class FooBarTest extends LegacyTestCase {
|
||||||
txn.commit();
|
txn.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
getSessions().evict(Glarch.class);
|
sessionFactory().evict(Glarch.class);
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
txn = s.beginTransaction();
|
txn = s.beginTransaction();
|
||||||
|
@ -3221,7 +3221,7 @@ public class FooBarTest extends LegacyTestCase {
|
||||||
txn.commit();
|
txn.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
getSessions().evict(Glarch.class);
|
sessionFactory().evict(Glarch.class);
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
txn = s.beginTransaction();
|
txn = s.beginTransaction();
|
||||||
|
@ -4337,7 +4337,7 @@ public class FooBarTest extends LegacyTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testUserProvidedConnection() throws Exception {
|
public void testUserProvidedConnection() throws Exception {
|
||||||
ConnectionProvider dcp = ConnectionProviderBuilder.buildConnectionProvider();
|
ConnectionProvider dcp = ConnectionProviderBuilder.buildConnectionProvider();
|
||||||
Session s = getSessions().openSession( dcp.getConnection() );
|
Session s = sessionFactory().openSession( dcp.getConnection() );
|
||||||
Transaction tx = s.beginTransaction();
|
Transaction tx = s.beginTransaction();
|
||||||
s.createQuery( "from Fo" ).list();
|
s.createQuery( "from Fo" ).list();
|
||||||
tx.commit();
|
tx.commit();
|
||||||
|
|
|
@ -733,7 +733,7 @@ public class FumTest extends LegacyTestCase {
|
||||||
public void testUnflushedSessionSerialization() throws Exception {
|
public void testUnflushedSessionSerialization() throws Exception {
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// Test insertions across serializations
|
// Test insertions across serializations
|
||||||
Session s = getSessions().openSession();
|
Session s = sessionFactory().openSession();
|
||||||
s.setFlushMode(FlushMode.MANUAL);
|
s.setFlushMode(FlushMode.MANUAL);
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
|
|
||||||
|
@ -766,7 +766,7 @@ public class FumTest extends LegacyTestCase {
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// Test updates across serializations
|
// Test updates across serializations
|
||||||
s = getSessions().openSession();
|
s = sessionFactory().openSession();
|
||||||
s.setFlushMode(FlushMode.MANUAL);
|
s.setFlushMode(FlushMode.MANUAL);
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
|
|
||||||
|
@ -789,7 +789,7 @@ public class FumTest extends LegacyTestCase {
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// Test deletions across serializations
|
// Test deletions across serializations
|
||||||
s = getSessions().openSession();
|
s = sessionFactory().openSession();
|
||||||
s.setFlushMode(FlushMode.MANUAL);
|
s.setFlushMode(FlushMode.MANUAL);
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
|
|
||||||
|
@ -812,7 +812,7 @@ public class FumTest extends LegacyTestCase {
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// Test collection actions across serializations
|
// Test collection actions across serializations
|
||||||
s = getSessions().openSession();
|
s = sessionFactory().openSession();
|
||||||
s.setFlushMode(FlushMode.MANUAL);
|
s.setFlushMode(FlushMode.MANUAL);
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
|
|
||||||
|
@ -842,7 +842,7 @@ public class FumTest extends LegacyTestCase {
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
s = getSessions().openSession();
|
s = sessionFactory().openSession();
|
||||||
s.setFlushMode(FlushMode.MANUAL);
|
s.setFlushMode(FlushMode.MANUAL);
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
fum = (Fum) s.load( Fum.class, fum.getId() );
|
fum = (Fum) s.load( Fum.class, fum.getId() );
|
||||||
|
@ -861,7 +861,7 @@ public class FumTest extends LegacyTestCase {
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
s = getSessions().openSession();
|
s = sessionFactory().openSession();
|
||||||
s.setFlushMode(FlushMode.MANUAL);
|
s.setFlushMode(FlushMode.MANUAL);
|
||||||
fum = (Fum) s.load( Fum.class, fum.getId() );
|
fum = (Fum) s.load( Fum.class, fum.getId() );
|
||||||
assertTrue("the Fum.friends is not empty", fum.getFriends() == null || fum.getFriends().size() == 0);
|
assertTrue("the Fum.friends is not empty", fum.getFriends() == null || fum.getFriends().size() == 0);
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class MasterDetailTest extends LegacyTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMeta() throws Exception {
|
public void testMeta() throws Exception {
|
||||||
PersistentClass clazz = getCfg().getClassMapping( Master.class.getName() );
|
PersistentClass clazz = configuration().getClassMapping( Master.class.getName() );
|
||||||
MetaAttribute meta = clazz.getMetaAttribute("foo");
|
MetaAttribute meta = clazz.getMetaAttribute("foo");
|
||||||
assertTrue( "foo".equals( meta.getValue() ) );
|
assertTrue( "foo".equals( meta.getValue() ) );
|
||||||
meta = clazz.getProperty("name").getMetaAttribute("bar");
|
meta = clazz.getProperty("name").getMetaAttribute("bar");
|
||||||
|
@ -873,13 +873,13 @@ public class MasterDetailTest extends LegacyTestCase {
|
||||||
protected boolean isSerializableIsolationEnforced() throws Exception {
|
protected boolean isSerializableIsolationEnforced() throws Exception {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = sfi().getConnectionProvider().getConnection();
|
conn = sessionFactory().getConnectionProvider().getConnection();
|
||||||
return conn.getTransactionIsolation() >= Connection.TRANSACTION_SERIALIZABLE;
|
return conn.getTransactionIsolation() >= Connection.TRANSACTION_SERIALIZABLE;
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if ( conn != null ) {
|
if ( conn != null ) {
|
||||||
try {
|
try {
|
||||||
sfi().getConnectionProvider().closeConnection( conn );
|
sessionFactory().getConnectionProvider().closeConnection( conn );
|
||||||
}
|
}
|
||||||
catch ( Throwable ignore ) {
|
catch ( Throwable ignore ) {
|
||||||
// ignore...
|
// ignore...
|
||||||
|
@ -1041,7 +1041,7 @@ public class MasterDetailTest extends LegacyTestCase {
|
||||||
s.connection().commit();
|
s.connection().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
getSessions().evictCollection("org.hibernate.test.legacy.Assignable.categories");
|
sessionFactory().evictCollection("org.hibernate.test.legacy.Assignable.categories");
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
a = (Assignable) s.get(Assignable.class, "foo");
|
a = (Assignable) s.get(Assignable.class, "foo");
|
||||||
|
@ -1054,7 +1054,7 @@ public class MasterDetailTest extends LegacyTestCase {
|
||||||
s.connection().commit();
|
s.connection().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
getSessions().evictCollection("org.hibernate.test.legacy.Assignable.categories");
|
sessionFactory().evictCollection("org.hibernate.test.legacy.Assignable.categories");
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
a = (Assignable) s.get(Assignable.class, "foo");
|
a = (Assignable) s.get(Assignable.class, "foo");
|
||||||
|
@ -1068,7 +1068,7 @@ public class MasterDetailTest extends LegacyTestCase {
|
||||||
s.connection().commit();
|
s.connection().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
getSessions().evictCollection("org.hibernate.test.legacy.Assignable.categories");
|
sessionFactory().evictCollection("org.hibernate.test.legacy.Assignable.categories");
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
a = (Assignable) s.get(Assignable.class, "foo");
|
a = (Assignable) s.get(Assignable.class, "foo");
|
||||||
|
|
|
@ -117,7 +117,7 @@ public class MultiTableTest extends LegacyTestCase {
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
getSessions().evict(SubMulti.class);
|
sessionFactory().evict(SubMulti.class);
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class OneToOneCacheTest extends LegacyTestCase {
|
||||||
assertNotNull( mainObject.getObj2() );
|
assertNotNull( mainObject.getObj2() );
|
||||||
|
|
||||||
// after evicting, it works.
|
// after evicting, it works.
|
||||||
getSessions().evict( MainObject.class );
|
sessionFactory().evict( MainObject.class );
|
||||||
|
|
||||||
mainObject = readMainObject();
|
mainObject = readMainObject();
|
||||||
|
|
||||||
|
|
|
@ -1194,7 +1194,7 @@ public class ParentChildTest extends LegacyTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next, lets create that entity "under the covers"
|
// Next, lets create that entity "under the covers"
|
||||||
Session anotherSession = getSessions().openSession();
|
Session anotherSession = sessionFactory().openSession();
|
||||||
anotherSession.beginTransaction();
|
anotherSession.beginTransaction();
|
||||||
Simple myNewSimple = new Simple();
|
Simple myNewSimple = new Simple();
|
||||||
myNewSimple.setName("My under the radar Simple entity");
|
myNewSimple.setName("My under the radar Simple entity");
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
getSessions().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
|
@ -123,9 +123,9 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 );
|
assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 1 );
|
||||||
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
|
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 0 );
|
||||||
assertEquals( getSessions().getStatistics().getQueryCachePutCount(), 1 );
|
assertEquals( sessionFactory().getStatistics().getQueryCachePutCount(), 1 );
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
|
@ -134,7 +134,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
getSessions().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
|
@ -143,15 +143,15 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
|
||||||
.setCacheable( true )
|
.setCacheable( true )
|
||||||
.uniqueResult();
|
.uniqueResult();
|
||||||
assertNotNull( u );
|
assertNotNull( u );
|
||||||
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 0 );
|
assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 0 );
|
||||||
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 1 );
|
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 1 );
|
||||||
u = ( User ) s.createCriteria( User.class )
|
u = ( User ) s.createCriteria( User.class )
|
||||||
.add( Restrictions.naturalId().set( "userName", "steve" ) )
|
.add( Restrictions.naturalId().set( "userName", "steve" ) )
|
||||||
.setCacheable( true )
|
.setCacheable( true )
|
||||||
.uniqueResult();
|
.uniqueResult();
|
||||||
assertNotNull( u );
|
assertNotNull( u );
|
||||||
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 0 );
|
assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 0 );
|
||||||
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 2 );
|
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 2 );
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
getSessions().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
|
@ -183,11 +183,11 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 );
|
assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 1 );
|
||||||
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
|
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 0 );
|
||||||
assertEquals( getSessions().getStatistics().getQueryCachePutCount(), 1 );
|
assertEquals( sessionFactory().getStatistics().getQueryCachePutCount(), 1 );
|
||||||
|
|
||||||
getSessions().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
|
@ -196,8 +196,8 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
|
||||||
.setCacheable( true )
|
.setCacheable( true )
|
||||||
.uniqueResult();
|
.uniqueResult();
|
||||||
assertNotNull( u );
|
assertNotNull( u );
|
||||||
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 0 );
|
assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 0 );
|
||||||
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 1 );
|
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 1 );
|
||||||
|
|
||||||
s.delete( u );
|
s.delete( u );
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
getSessions().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
|
@ -236,11 +236,11 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
|
||||||
.uniqueResult();
|
.uniqueResult();
|
||||||
assertNotNull( u );
|
assertNotNull( u );
|
||||||
|
|
||||||
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 );
|
assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 1 );
|
||||||
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
|
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 0 );
|
||||||
assertEquals( getSessions().getStatistics().getQueryCachePutCount(), 1 );
|
assertEquals( sessionFactory().getStatistics().getQueryCachePutCount(), 1 );
|
||||||
|
|
||||||
getSessions().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
|
@ -249,8 +249,8 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
|
||||||
.setCacheable( true )
|
.setCacheable( true )
|
||||||
.uniqueResult();
|
.uniqueResult();
|
||||||
assertNotNull( u );
|
assertNotNull( u );
|
||||||
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 0 );
|
assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 0 );
|
||||||
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 1 );
|
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 1 );
|
||||||
|
|
||||||
s.delete( u );
|
s.delete( u );
|
||||||
|
|
||||||
|
|
|
@ -80,26 +80,26 @@ public abstract class AbstractOperationTestCase extends BaseCoreFunctionalTestCa
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void clearCounts() {
|
protected void clearCounts() {
|
||||||
getSessions().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertInsertCount(int expected) {
|
protected void assertInsertCount(int expected) {
|
||||||
int inserts = ( int ) getSessions().getStatistics().getEntityInsertCount();
|
int inserts = ( int ) sessionFactory().getStatistics().getEntityInsertCount();
|
||||||
assertEquals( "unexpected insert count", expected, inserts );
|
assertEquals( "unexpected insert count", expected, inserts );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertUpdateCount(int expected) {
|
protected void assertUpdateCount(int expected) {
|
||||||
int updates = ( int ) getSessions().getStatistics().getEntityUpdateCount();
|
int updates = ( int ) sessionFactory().getStatistics().getEntityUpdateCount();
|
||||||
assertEquals( "unexpected update counts", expected, updates );
|
assertEquals( "unexpected update counts", expected, updates );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertDeleteCount(int expected) {
|
protected void assertDeleteCount(int expected) {
|
||||||
int deletes = ( int ) getSessions().getStatistics().getEntityDeleteCount();
|
int deletes = ( int ) sessionFactory().getStatistics().getEntityDeleteCount();
|
||||||
assertEquals( "unexpected delete counts", expected, deletes );
|
assertEquals( "unexpected delete counts", expected, deletes );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertFetchCount(int count) {
|
protected void assertFetchCount(int count) {
|
||||||
int fetches = ( int ) getSessions().getStatistics().getEntityFetchCount();
|
int fetches = ( int ) sessionFactory().getStatistics().getEntityFetchCount();
|
||||||
assertEquals( count, fetches );
|
assertEquals( count, fetches );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
//$Id: MergeTest.java 11037 2007-01-09 16:04:16Z steve.ebersole@jboss.com $
|
//$Id: MergeTest.java 11037 2007-01-09 16:04:16Z steve.ebersole@jboss.com $
|
||||||
package org.hibernate.test.nonflushedchanges;
|
package org.hibernate.test.nonflushedchanges;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -493,7 +492,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
assertUpdateCount( 1 );
|
assertUpdateCount( 1 );
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
getSessions().getCache().evictEntityRegion( NumberedNode.class );
|
sessionFactory().getCache().evictEntityRegion( NumberedNode.class );
|
||||||
|
|
||||||
NumberedNode child2 = new NumberedNode( "child2" );
|
NumberedNode child2 = new NumberedNode( "child2" );
|
||||||
NumberedNode grandchild3 = new NumberedNode( "grandchild3" );
|
NumberedNode grandchild3 = new NumberedNode( "grandchild3" );
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class OnDeleteTest extends BaseCoreFunctionalTestCase {
|
||||||
comment = "db/dialect does not support circular cascade delete constraints"
|
comment = "db/dialect does not support circular cascade delete constraints"
|
||||||
)
|
)
|
||||||
public void testJoinedSubclass() {
|
public void testJoinedSubclass() {
|
||||||
Statistics statistics = getSessions().getStatistics();
|
Statistics statistics = sessionFactory().getStatistics();
|
||||||
statistics.clear();
|
statistics.clear();
|
||||||
|
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
|
|
|
@ -71,8 +71,8 @@ public class JoinedSubclassOneToOneTest extends BaseCoreFunctionalTestCase {
|
||||||
s = openSession();
|
s = openSession();
|
||||||
t = s.beginTransaction();
|
t = s.beginTransaction();
|
||||||
|
|
||||||
EntityStatistics addressStats = getSessions().getStatistics().getEntityStatistics( Address.class.getName() );
|
EntityStatistics addressStats = sessionFactory().getStatistics().getEntityStatistics( Address.class.getName() );
|
||||||
EntityStatistics mailingAddressStats = getSessions().getStatistics().getEntityStatistics("MailingAddress");
|
EntityStatistics mailingAddressStats = sessionFactory().getStatistics().getEntityStatistics("MailingAddress");
|
||||||
|
|
||||||
p = (Person) s.createQuery("from Person p join fetch p.address left join fetch p.mailingAddress").uniqueResult();
|
p = (Person) s.createQuery("from Person p join fetch p.address left join fetch p.mailingAddress").uniqueResult();
|
||||||
assertNotNull(p.address); assertNull(p.mailingAddress);
|
assertNotNull(p.address); assertNull(p.mailingAddress);
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class DynamicMapOneToOneTest extends BaseCoreFunctionalTestCase {
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
|
|
||||||
EntityStatistics addressStats = getSessions().getStatistics().getEntityStatistics( "Address" );
|
EntityStatistics addressStats = sessionFactory().getStatistics().getEntityStatistics( "Address" );
|
||||||
|
|
||||||
person = ( Map ) s.createQuery( "from Person p join fetch p.address" ).uniqueResult();
|
person = ( Map ) s.createQuery( "from Person p join fetch p.address" ).uniqueResult();
|
||||||
assertNotNull( "could not locate person", person );
|
assertNotNull( "could not locate person", person );
|
||||||
|
|
|
@ -73,8 +73,8 @@ public class DiscrimSubclassOneToOneTest extends BaseCoreFunctionalTestCase {
|
||||||
s = openSession();
|
s = openSession();
|
||||||
t = s.beginTransaction();
|
t = s.beginTransaction();
|
||||||
|
|
||||||
EntityStatistics addressStats = getSessions().getStatistics().getEntityStatistics( Address.class.getName() );
|
EntityStatistics addressStats = sessionFactory().getStatistics().getEntityStatistics( Address.class.getName() );
|
||||||
EntityStatistics mailingAddressStats = getSessions().getStatistics().getEntityStatistics("MailingAddress");
|
EntityStatistics mailingAddressStats = sessionFactory().getStatistics().getEntityStatistics("MailingAddress");
|
||||||
|
|
||||||
p = (Person) s.createQuery("from Person p join fetch p.address left join fetch p.mailingAddress").uniqueResult();
|
p = (Person) s.createQuery("from Person p join fetch p.address left join fetch p.mailingAddress").uniqueResult();
|
||||||
assertNotNull(p.address); assertNull(p.mailingAddress);
|
assertNotNull(p.address); assertNull(p.mailingAddress);
|
||||||
|
|
|
@ -47,21 +47,21 @@ public abstract class AbstractOperationTestCase extends BaseCoreFunctionalTestCa
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void clearCounts() {
|
protected void clearCounts() {
|
||||||
getSessions().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertInsertCount(int expected) {
|
protected void assertInsertCount(int expected) {
|
||||||
int inserts = ( int ) getSessions().getStatistics().getEntityInsertCount();
|
int inserts = ( int ) sessionFactory().getStatistics().getEntityInsertCount();
|
||||||
assertEquals( "unexpected insert count", expected, inserts );
|
assertEquals( "unexpected insert count", expected, inserts );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertUpdateCount(int expected) {
|
protected void assertUpdateCount(int expected) {
|
||||||
int updates = ( int ) getSessions().getStatistics().getEntityUpdateCount();
|
int updates = ( int ) sessionFactory().getStatistics().getEntityUpdateCount();
|
||||||
assertEquals( "unexpected update counts", expected, updates );
|
assertEquals( "unexpected update counts", expected, updates );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertDeleteCount(int expected) {
|
protected void assertDeleteCount(int expected) {
|
||||||
int deletes = ( int ) getSessions().getStatistics().getEntityDeleteCount();
|
int deletes = ( int ) sessionFactory().getStatistics().getEntityDeleteCount();
|
||||||
assertEquals( "unexpected delete counts", expected, deletes );
|
assertEquals( "unexpected delete counts", expected, deletes );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -505,7 +505,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
assertUpdateCount(1);
|
assertUpdateCount(1);
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
getSessions().getCache().evictEntityRegion( NumberedNode.class );
|
sessionFactory().getCache().evictEntityRegion( NumberedNode.class );
|
||||||
|
|
||||||
NumberedNode child2 = new NumberedNode("child2");
|
NumberedNode child2 = new NumberedNode("child2");
|
||||||
NumberedNode grandchild3 = new NumberedNode("grandchild3");
|
NumberedNode grandchild3 = new NumberedNode("grandchild3");
|
||||||
|
|
|
@ -271,8 +271,8 @@ public class OrphanTest extends BaseCoreFunctionalTestCase {
|
||||||
t.commit();
|
t.commit();
|
||||||
session.close();
|
session.close();
|
||||||
|
|
||||||
getSessions().getCache().evictEntityRegion( Product.class );
|
sessionFactory().getCache().evictEntityRegion( Product.class );
|
||||||
getSessions().getCache().evictEntityRegion( Part.class );
|
sessionFactory().getCache().evictEntityRegion( Part.class );
|
||||||
|
|
||||||
|
|
||||||
session = openSession();
|
session = openSession();
|
||||||
|
|
|
@ -241,18 +241,18 @@ public class PropertyRefTest extends BaseCoreFunctionalTestCase {
|
||||||
s.flush();
|
s.flush();
|
||||||
s.clear();
|
s.clear();
|
||||||
|
|
||||||
getSessions().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
|
|
||||||
p = (Person) s.get( Person.class, p.getId() ); //get address reference by outer join
|
p = (Person) s.get( Person.class, p.getId() ); //get address reference by outer join
|
||||||
|
|
||||||
assertTrue( Hibernate.isInitialized( p.getAddress() ) );
|
assertTrue( Hibernate.isInitialized( p.getAddress() ) );
|
||||||
assertNotNull( p.getAddress() );
|
assertNotNull( p.getAddress() );
|
||||||
assertEquals( getSessions().getStatistics().getPrepareStatementCount(), 1 );
|
assertEquals( sessionFactory().getStatistics().getPrepareStatementCount(), 1 );
|
||||||
assertEquals( getSessions().getStatistics().getEntityFetchCount(), 0 );
|
assertEquals( sessionFactory().getStatistics().getEntityFetchCount(), 0 );
|
||||||
|
|
||||||
s.clear();
|
s.clear();
|
||||||
|
|
||||||
getSessions().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
|
|
||||||
p = (Person) s.createCriteria(Person.class)
|
p = (Person) s.createCriteria(Person.class)
|
||||||
.setFetchMode("address", FetchMode.SELECT)
|
.setFetchMode("address", FetchMode.SELECT)
|
||||||
|
@ -260,8 +260,8 @@ public class PropertyRefTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
assertTrue( Hibernate.isInitialized( p.getAddress() ) );
|
assertTrue( Hibernate.isInitialized( p.getAddress() ) );
|
||||||
assertNotNull( p.getAddress() );
|
assertNotNull( p.getAddress() );
|
||||||
assertEquals( getSessions().getStatistics().getPrepareStatementCount(), 2 );
|
assertEquals( sessionFactory().getStatistics().getPrepareStatementCount(), 2 );
|
||||||
assertEquals( getSessions().getStatistics().getEntityFetchCount(), 0 );
|
assertEquals( sessionFactory().getStatistics().getEntityFetchCount(), 0 );
|
||||||
|
|
||||||
s.createQuery("delete from Address").executeUpdate();
|
s.createQuery("delete from Address").executeUpdate();
|
||||||
s.createQuery("delete from Person").executeUpdate();
|
s.createQuery("delete from Person").executeUpdate();
|
||||||
|
@ -272,7 +272,7 @@ public class PropertyRefTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testForeignKeyCreation() {
|
public void testForeignKeyCreation() {
|
||||||
PersistentClass classMapping = getCfg().getClassMapping("org.hibernate.test.propertyref.basic.Account");
|
PersistentClass classMapping = configuration().getClassMapping("org.hibernate.test.propertyref.basic.Account");
|
||||||
|
|
||||||
Iterator foreignKeyIterator = classMapping.getTable().getForeignKeyIterator();
|
Iterator foreignKeyIterator = classMapping.getTable().getForeignKeyIterator();
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
|
|
|
@ -2219,7 +2219,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
|
||||||
}
|
}
|
||||||
private Constructor getConstructor() {
|
private Constructor getConstructor() {
|
||||||
Type studentNametype =
|
Type studentNametype =
|
||||||
( ( SessionFactoryImpl ) getSessions() )
|
( ( SessionFactoryImpl ) sessionFactory() )
|
||||||
.getEntityPersister( Student.class.getName() )
|
.getEntityPersister( Student.class.getName() )
|
||||||
.getPropertyType( "name" );
|
.getPropertyType( "name" );
|
||||||
return ReflectHelper.getConstructor( Student.class, new Type[] {Hibernate.LONG, studentNametype} );
|
return ReflectHelper.getConstructor( Student.class, new Type[] {Hibernate.LONG, studentNametype} );
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class NativeSQLQueryPlanEqualsTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNativeSQLQuerySpecEquals() {
|
public void testNativeSQLQuerySpecEquals() {
|
||||||
QueryPlanCache cache = new QueryPlanCache( sfi() );
|
QueryPlanCache cache = new QueryPlanCache( sessionFactory() );
|
||||||
NativeSQLQuerySpecification firstSpec = createSpec();
|
NativeSQLQuerySpecification firstSpec = createSpec();
|
||||||
|
|
||||||
NativeSQLQuerySpecification secondSpec = createSpec();
|
NativeSQLQuerySpecification secondSpec = createSpec();
|
||||||
|
@ -63,7 +63,7 @@ public class NativeSQLQueryPlanEqualsTest extends BaseCoreFunctionalTestCase {
|
||||||
String blah = "blah";
|
String blah = "blah";
|
||||||
String select = "select blah from blah";
|
String select = "select blah from blah";
|
||||||
NativeSQLQueryReturn[] queryReturns = new NativeSQLQueryScalarReturn[] {
|
NativeSQLQueryReturn[] queryReturns = new NativeSQLQueryScalarReturn[] {
|
||||||
new NativeSQLQueryScalarReturn( blah, sfi().getTypeResolver().basic( "int" ) )
|
new NativeSQLQueryScalarReturn( blah, sessionFactory().getTypeResolver().basic( "int" ) )
|
||||||
};
|
};
|
||||||
return new NativeSQLQuerySpecification( select, queryReturns, null );
|
return new NativeSQLQuerySpecification( select, queryReturns, null );
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class RowIdTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
public void afterSessionFactoryBuilt() {
|
public void afterSessionFactoryBuilt() {
|
||||||
super.afterSessionFactoryBuilt();
|
super.afterSessionFactoryBuilt();
|
||||||
Session session = sfi().openSession();
|
Session session = sessionFactory().openSession();
|
||||||
session.doWork(
|
session.doWork(
|
||||||
new Work() {
|
new Work() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -78,9 +78,9 @@ public abstract class CustomSQLTestSupport extends BaseCoreFunctionalTestCase {
|
||||||
t.commit();
|
t.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
getSessions().getCache().evictEntityRegion( Organization.class );
|
sessionFactory().getCache().evictEntityRegion( Organization.class );
|
||||||
getSessions().getCache().evictEntityRegion( Person.class );
|
sessionFactory().getCache().evictEntityRegion( Person.class );
|
||||||
getSessions().getCache().evictEntityRegion( Employment.class );
|
sessionFactory().getCache().evictEntityRegion( Employment.class );
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
t = s.beginTransaction();
|
t = s.beginTransaction();
|
||||||
|
|
|
@ -146,7 +146,7 @@ public class NativeSQLQueriesTest extends BaseCoreFunctionalTestCase {
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
|
|
||||||
sfi().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
|
|
||||||
// create an Organization...
|
// create an Organization...
|
||||||
Organization jboss = new Organization( "JBoss" );
|
Organization jboss = new Organization( "JBoss" );
|
||||||
|
@ -154,11 +154,11 @@ public class NativeSQLQueriesTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
// now query on Employment, this should not cause an auto-flush
|
// now query on Employment, this should not cause an auto-flush
|
||||||
s.createSQLQuery( getEmploymentSQL() ).list();
|
s.createSQLQuery( getEmploymentSQL() ).list();
|
||||||
assertEquals( 0, sfi().getStatistics().getEntityInsertCount() );
|
assertEquals( 0, sessionFactory().getStatistics().getEntityInsertCount() );
|
||||||
|
|
||||||
// now try to query on Employment but this time add Organization as a synchronized query space...
|
// now try to query on Employment but this time add Organization as a synchronized query space...
|
||||||
s.createSQLQuery( getEmploymentSQL() ).addSynchronizedEntityClass( Organization.class ).list();
|
s.createSQLQuery( getEmploymentSQL() ).addSynchronizedEntityClass( Organization.class ).list();
|
||||||
assertEquals( 1, sfi().getStatistics().getEntityInsertCount() );
|
assertEquals( 1, sessionFactory().getStatistics().getEntityInsertCount() );
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
s.delete( jboss );
|
s.delete( jboss );
|
||||||
|
|
|
@ -52,8 +52,8 @@ public class NativeSqlAndQuotedIdentifiersTest extends BaseCoreFunctionalTestCas
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void prepareTest() throws Exception {
|
protected void prepareTest() throws Exception {
|
||||||
if(sfi()==null)return;
|
if( sessionFactory()==null)return;
|
||||||
Session session = sfi().openSession();
|
Session session = sessionFactory().openSession();
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
session.save( new Person( "me" ) );
|
session.save( new Person( "me" ) );
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
|
@ -62,8 +62,8 @@ public class NativeSqlAndQuotedIdentifiersTest extends BaseCoreFunctionalTestCas
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void cleanupTest() throws Exception {
|
protected void cleanupTest() throws Exception {
|
||||||
if(sfi()==null)return;
|
if( sessionFactory()==null)return;
|
||||||
Session session = sfi().openSession();
|
Session session = sessionFactory().openSession();
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
session.createQuery( "delete Person" ).executeUpdate();
|
session.createQuery( "delete Person" ).executeUpdate();
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class StatelessSessionQueryTest extends BaseCoreFunctionalTestCase {
|
||||||
public void testCriteria() {
|
public void testCriteria() {
|
||||||
TestData testData=new TestData();
|
TestData testData=new TestData();
|
||||||
testData.createData();
|
testData.createData();
|
||||||
StatelessSession s = getSessions().openStatelessSession();
|
StatelessSession s = sessionFactory().openStatelessSession();
|
||||||
assertEquals( 1, s.createCriteria( Contact.class ).list().size() );
|
assertEquals( 1, s.createCriteria( Contact.class ).list().size() );
|
||||||
s.close();
|
s.close();
|
||||||
testData.cleanData();
|
testData.cleanData();
|
||||||
|
@ -66,7 +66,7 @@ public class StatelessSessionQueryTest extends BaseCoreFunctionalTestCase {
|
||||||
public void testCriteriaWithSelectFetchMode() {
|
public void testCriteriaWithSelectFetchMode() {
|
||||||
TestData testData=new TestData();
|
TestData testData=new TestData();
|
||||||
testData.createData();
|
testData.createData();
|
||||||
StatelessSession s = getSessions().openStatelessSession();
|
StatelessSession s = sessionFactory().openStatelessSession();
|
||||||
assertEquals( 1, s.createCriteria( Contact.class ).setFetchMode( "org", FetchMode.SELECT )
|
assertEquals( 1, s.createCriteria( Contact.class ).setFetchMode( "org", FetchMode.SELECT )
|
||||||
.list().size() );
|
.list().size() );
|
||||||
s.close();
|
s.close();
|
||||||
|
@ -77,7 +77,7 @@ public class StatelessSessionQueryTest extends BaseCoreFunctionalTestCase {
|
||||||
public void testHQL() {
|
public void testHQL() {
|
||||||
TestData testData=new TestData();
|
TestData testData=new TestData();
|
||||||
testData.createData();
|
testData.createData();
|
||||||
StatelessSession s = getSessions().openStatelessSession();
|
StatelessSession s = sessionFactory().openStatelessSession();
|
||||||
assertEquals( 1, s.createQuery( "from Contact c join fetch c.org join fetch c.org.country" )
|
assertEquals( 1, s.createQuery( "from Contact c join fetch c.org join fetch c.org.country" )
|
||||||
.list().size() );
|
.list().size() );
|
||||||
s.close();
|
s.close();
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class StatelessSessionTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateUpdateReadDelete() {
|
public void testCreateUpdateReadDelete() {
|
||||||
StatelessSession ss = getSessions().openStatelessSession();
|
StatelessSession ss = sessionFactory().openStatelessSession();
|
||||||
Transaction tx = ss.beginTransaction();
|
Transaction tx = ss.beginTransaction();
|
||||||
Document doc = new Document("blah blah blah", "Blahs");
|
Document doc = new Document("blah blah blah", "Blahs");
|
||||||
ss.insert(doc);
|
ss.insert(doc);
|
||||||
|
@ -109,7 +109,7 @@ public class StatelessSessionTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHqlBulk() {
|
public void testHqlBulk() {
|
||||||
StatelessSession ss = getSessions().openStatelessSession();
|
StatelessSession ss = sessionFactory().openStatelessSession();
|
||||||
Transaction tx = ss.beginTransaction();
|
Transaction tx = ss.beginTransaction();
|
||||||
Document doc = new Document("blah blah blah", "Blahs");
|
Document doc = new Document("blah blah blah", "Blahs");
|
||||||
ss.insert(doc);
|
ss.insert(doc);
|
||||||
|
@ -141,7 +141,7 @@ public class StatelessSessionTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInitId() {
|
public void testInitId() {
|
||||||
StatelessSession ss = getSessions().openStatelessSession();
|
StatelessSession ss = sessionFactory().openStatelessSession();
|
||||||
Transaction tx = ss.beginTransaction();
|
Transaction tx = ss.beginTransaction();
|
||||||
Paper paper = new Paper();
|
Paper paper = new Paper();
|
||||||
paper.setColor( "White" );
|
paper.setColor( "White" );
|
||||||
|
@ -157,7 +157,7 @@ public class StatelessSessionTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRefresh() {
|
public void testRefresh() {
|
||||||
StatelessSession ss = getSessions().openStatelessSession();
|
StatelessSession ss = sessionFactory().openStatelessSession();
|
||||||
Transaction tx = ss.beginTransaction();
|
Transaction tx = ss.beginTransaction();
|
||||||
Paper paper = new Paper();
|
Paper paper = new Paper();
|
||||||
paper.setColor( "whtie" );
|
paper.setColor( "whtie" );
|
||||||
|
@ -165,7 +165,7 @@ public class StatelessSessionTest extends BaseCoreFunctionalTestCase {
|
||||||
tx.commit();
|
tx.commit();
|
||||||
ss.close();
|
ss.close();
|
||||||
|
|
||||||
ss = getSessions().openStatelessSession();
|
ss = sessionFactory().openStatelessSession();
|
||||||
tx = ss.beginTransaction();
|
tx = ss.beginTransaction();
|
||||||
Paper p2 = ( Paper ) ss.get( Paper.class, paper.getId() );
|
Paper p2 = ( Paper ) ss.get( Paper.class, paper.getId() );
|
||||||
p2.setColor( "White" );
|
p2.setColor( "White" );
|
||||||
|
@ -173,7 +173,7 @@ public class StatelessSessionTest extends BaseCoreFunctionalTestCase {
|
||||||
tx.commit();
|
tx.commit();
|
||||||
ss.close();
|
ss.close();
|
||||||
|
|
||||||
ss = getSessions().openStatelessSession();
|
ss = sessionFactory().openStatelessSession();
|
||||||
tx = ss.beginTransaction();
|
tx = ss.beginTransaction();
|
||||||
assertEquals( "whtie", paper.getColor() );
|
assertEquals( "whtie", paper.getColor() );
|
||||||
ss.refresh( paper );
|
ss.refresh( paper );
|
||||||
|
|
|
@ -114,7 +114,7 @@ public class StatelessSessionFetchingTest extends BaseCoreFunctionalTestCase {
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
StatelessSession ss = sfi().openStatelessSession();
|
StatelessSession ss = sessionFactory().openStatelessSession();
|
||||||
ss.beginTransaction();
|
ss.beginTransaction();
|
||||||
Task taskRef = ( Task ) ss.createQuery( "from Task t join fetch t.resource join fetch t.user" ).uniqueResult();
|
Task taskRef = ( Task ) ss.createQuery( "from Task t join fetch t.resource join fetch t.user" ).uniqueResult();
|
||||||
assertTrue( taskRef != null );
|
assertTrue( taskRef != null );
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class StatsTest extends BaseCoreFunctionalTestCase {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings( {"UnusedAssignment"})
|
@SuppressWarnings( {"UnusedAssignment"})
|
||||||
public void testCollectionFetchVsLoad() throws Exception {
|
public void testCollectionFetchVsLoad() throws Exception {
|
||||||
Statistics stats = getSessions().getStatistics();
|
Statistics stats = sessionFactory().getStatistics();
|
||||||
stats.clear();
|
stats.clear();
|
||||||
|
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
|
@ -151,7 +151,7 @@ public class StatsTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQueryStatGathering() {
|
public void testQueryStatGathering() {
|
||||||
Statistics stats = getSessions().getStatistics();
|
Statistics stats = sessionFactory().getStatistics();
|
||||||
stats.clear();
|
stats.clear();
|
||||||
|
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class SubselectTest extends BaseCoreFunctionalTestCase {
|
||||||
assertNotNull( being.getSpecies() );
|
assertNotNull( being.getSpecies() );
|
||||||
}
|
}
|
||||||
s.clear();
|
s.clear();
|
||||||
getSessions().getCache().evictEntityRegion( Being.class );
|
sessionFactory().getCache().evictEntityRegion( Being.class );
|
||||||
Being gav = (Being) s.get(Being.class, gavin.getId());
|
Being gav = (Being) s.get(Being.class, gavin.getId());
|
||||||
assertEquals( gav.getLocation(), gavin.getAddress() );
|
assertEquals( gav.getLocation(), gavin.getAddress() );
|
||||||
assertEquals( gav.getSpecies(), "human" );
|
assertEquals( gav.getSpecies(), "human" );
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class TimestampTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateFalse() {
|
public void testUpdateFalse() {
|
||||||
getSessions().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
|
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Transaction t = s.beginTransaction();
|
Transaction t = s.beginTransaction();
|
||||||
|
@ -61,8 +61,8 @@ public class TimestampTest extends BaseCoreFunctionalTestCase {
|
||||||
t.commit();
|
t.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
assertEquals( 1, getSessions().getStatistics().getEntityInsertCount() );
|
assertEquals( 1, sessionFactory().getStatistics().getEntityInsertCount() );
|
||||||
assertEquals( 0, getSessions().getStatistics().getEntityUpdateCount() );
|
assertEquals( 0, sessionFactory().getStatistics().getEntityUpdateCount() );
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
t = s.beginTransaction();
|
t = s.beginTransaction();
|
||||||
|
@ -72,7 +72,7 @@ public class TimestampTest extends BaseCoreFunctionalTestCase {
|
||||||
t.commit();
|
t.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
assertEquals( 1, getSessions().getStatistics().getEntityDeleteCount() );
|
assertEquals( 1, sessionFactory().getStatistics().getEntityDeleteCount() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -133,7 +133,7 @@ public class TypeOverrideTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private SqlTypeDescriptor getResolvedSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
|
private SqlTypeDescriptor getResolvedSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
|
||||||
return ( ( SessionFactoryImplementor ) getSessions() )
|
return ( ( SessionFactoryImplementor ) sessionFactory() )
|
||||||
.getTypeResolver()
|
.getTypeResolver()
|
||||||
.resolveSqlTypeDescriptor( sqlTypeDescriptor );
|
.resolveSqlTypeDescriptor( sqlTypeDescriptor );
|
||||||
}
|
}
|
||||||
|
@ -197,7 +197,7 @@ public class TypeOverrideTest extends BaseCoreFunctionalTestCase {
|
||||||
else {
|
else {
|
||||||
assertSame(
|
assertSame(
|
||||||
VarcharTypeDescriptor.INSTANCE,
|
VarcharTypeDescriptor.INSTANCE,
|
||||||
( ( SessionFactoryImplementor ) getSessions() )
|
( ( SessionFactoryImplementor ) sessionFactory() )
|
||||||
.getTypeResolver()
|
.getTypeResolver()
|
||||||
.resolveSqlTypeDescriptor( VarcharTypeDescriptor.INSTANCE )
|
.resolveSqlTypeDescriptor( VarcharTypeDescriptor.INSTANCE )
|
||||||
);
|
);
|
||||||
|
|
|
@ -65,9 +65,9 @@ public class SybaseTimestampVersioningTest extends BaseCoreFunctionalTestCase {
|
||||||
Transaction t1 = null;
|
Transaction t1 = null;
|
||||||
Transaction t2 = null;
|
Transaction t2 = null;
|
||||||
try {
|
try {
|
||||||
s1 = getSessions().openSession();
|
s1 = sessionFactory().openSession();
|
||||||
t1 = s1.beginTransaction();
|
t1 = s1.beginTransaction();
|
||||||
s2 = getSessions().openSession();
|
s2 = sessionFactory().openSession();
|
||||||
t2 = s2.beginTransaction();
|
t2 = s2.beginTransaction();
|
||||||
|
|
||||||
User user1 = ( User ) s1.get( User.class, steve.getId() );
|
User user1 = ( User ) s1.get( User.class, steve.getId() );
|
||||||
|
|
|
@ -180,7 +180,7 @@ public class EhCacheTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the version value in the cache...
|
// check the version value in the cache...
|
||||||
SecondLevelCacheStatistics slcs = sfi().getStatistics()
|
SecondLevelCacheStatistics slcs = sessionFactory().getStatistics()
|
||||||
.getSecondLevelCacheStatistics( VersionedItem.class.getName() );
|
.getSecondLevelCacheStatistics( VersionedItem.class.getName() );
|
||||||
|
|
||||||
Object entry = slcs.getEntries().get( item.getId() );
|
Object entry = slcs.getEntries().get( item.getId() );
|
||||||
|
|
|
@ -94,6 +94,7 @@ import org.hibernate.mapping.AuxiliaryDatabaseObject;
|
||||||
import org.hibernate.mapping.PersistentClass;
|
import org.hibernate.mapping.PersistentClass;
|
||||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||||
import org.hibernate.secure.JACCConfiguration;
|
import org.hibernate.secure.JACCConfiguration;
|
||||||
|
import org.hibernate.service.internal.ServiceRegistryImpl;
|
||||||
import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator;
|
import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator;
|
||||||
import org.hibernate.service.spi.ServiceRegistry;
|
import org.hibernate.service.spi.ServiceRegistry;
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
@ -871,6 +872,10 @@ public class Ejb3Configuration implements Serializable, Referenceable {
|
||||||
return buildEntityManagerFactory();
|
return buildEntityManagerFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EntityManagerFactory createEntityManagerFactory(Map config, ServiceRegistryImpl serviceRegistry) {
|
||||||
|
return null; // todo : implement method body
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process configuration and build an EntityManagerFactory <b>when</b> the configuration is ready
|
* Process configuration and build an EntityManagerFactory <b>when</b> the configuration is ready
|
||||||
* @deprecated
|
* @deprecated
|
||||||
|
@ -882,6 +887,10 @@ public class Ejb3Configuration implements Serializable, Referenceable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityManagerFactory buildEntityManagerFactory() {
|
public EntityManagerFactory buildEntityManagerFactory() {
|
||||||
|
return buildEntityManagerFactory( new ServiceRegistryImpl( cfg.getProperties() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityManagerFactory buildEntityManagerFactory(ServiceRegistry serviceRegistry) {
|
||||||
Thread thread = null;
|
Thread thread = null;
|
||||||
ClassLoader contextClassLoader = null;
|
ClassLoader contextClassLoader = null;
|
||||||
if (overridenClassLoader != null) {
|
if (overridenClassLoader != null) {
|
||||||
|
@ -897,7 +906,8 @@ public class Ejb3Configuration implements Serializable, Referenceable {
|
||||||
discardOnClose,
|
discardOnClose,
|
||||||
getSessionInterceptorClass( cfg.getProperties() ),
|
getSessionInterceptorClass( cfg.getProperties() ),
|
||||||
cfg,
|
cfg,
|
||||||
connectionProviderInjectionData
|
connectionProviderInjectionData,
|
||||||
|
serviceRegistry
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch (HibernateException e) {
|
catch (HibernateException e) {
|
||||||
|
|
|
@ -38,6 +38,7 @@ import javax.persistence.spi.PersistenceUnitTransactionType;
|
||||||
import org.hibernate.EntityMode;
|
import org.hibernate.EntityMode;
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.cfg.AnnotationConfiguration;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
|
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
|
||||||
import org.hibernate.ejb.metamodel.MetamodelImpl;
|
import org.hibernate.ejb.metamodel.MetamodelImpl;
|
||||||
|
@ -46,6 +47,7 @@ import org.hibernate.engine.SessionFactoryImplementor;
|
||||||
import org.hibernate.mapping.PersistentClass;
|
import org.hibernate.mapping.PersistentClass;
|
||||||
import org.hibernate.metadata.ClassMetadata;
|
import org.hibernate.metadata.ClassMetadata;
|
||||||
import org.hibernate.service.internal.ServiceRegistryImpl;
|
import org.hibernate.service.internal.ServiceRegistryImpl;
|
||||||
|
import org.hibernate.service.spi.ServiceRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Actual Hiberate implementation of {@link javax.persistence.EntityManagerFactory}.
|
* Actual Hiberate implementation of {@link javax.persistence.EntityManagerFactory}.
|
||||||
|
@ -55,7 +57,7 @@ import org.hibernate.service.internal.ServiceRegistryImpl;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
|
public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
|
||||||
private final transient ServiceRegistryImpl serviceRegistry;
|
private final transient ServiceRegistry serviceRegistry;
|
||||||
private final SessionFactory sessionFactory;
|
private final SessionFactory sessionFactory;
|
||||||
private final PersistenceUnitTransactionType transactionType;
|
private final PersistenceUnitTransactionType transactionType;
|
||||||
private final boolean discardOnClose;
|
private final boolean discardOnClose;
|
||||||
|
@ -72,16 +74,11 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
|
||||||
public EntityManagerFactoryImpl(
|
public EntityManagerFactoryImpl(
|
||||||
PersistenceUnitTransactionType transactionType,
|
PersistenceUnitTransactionType transactionType,
|
||||||
boolean discardOnClose,
|
boolean discardOnClose,
|
||||||
Class<?> sessionInterceptorClass,
|
Class sessionInterceptorClass,
|
||||||
Configuration cfg,
|
AnnotationConfiguration cfg,
|
||||||
Map connectionProviderInjectionData) {
|
Map connectionProviderInjectionData,
|
||||||
// FIXME: Get rid of this temporary way of creating the service registry for EM
|
ServiceRegistry serviceRegistry) {
|
||||||
Map serviceRegistryProperties = new HashMap(
|
this.serviceRegistry = serviceRegistry;
|
||||||
cfg.getProperties().size() + connectionProviderInjectionData.size()
|
|
||||||
);
|
|
||||||
serviceRegistryProperties.putAll( cfg.getProperties() );
|
|
||||||
serviceRegistryProperties.putAll( connectionProviderInjectionData );
|
|
||||||
this.serviceRegistry = new ServiceRegistryImpl( serviceRegistryProperties );
|
|
||||||
this.sessionFactory = cfg.buildSessionFactory( serviceRegistry );
|
this.sessionFactory = cfg.buildSessionFactory( serviceRegistry );
|
||||||
this.transactionType = transactionType;
|
this.transactionType = transactionType;
|
||||||
this.discardOnClose = discardOnClose;
|
this.discardOnClose = discardOnClose;
|
||||||
|
@ -134,7 +131,6 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
sessionFactory.close();
|
sessionFactory.close();
|
||||||
serviceRegistry.destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> getProperties() {
|
public Map<String, Object> getProperties() {
|
||||||
|
|
|
@ -42,7 +42,7 @@ import org.hibernate.ejb.metamodel.Phone;
|
||||||
import org.hibernate.ejb.metamodel.Product;
|
import org.hibernate.ejb.metamodel.Product;
|
||||||
import org.hibernate.ejb.metamodel.ShelfLife;
|
import org.hibernate.ejb.metamodel.ShelfLife;
|
||||||
import org.hibernate.ejb.metamodel.Spouse;
|
import org.hibernate.ejb.metamodel.Spouse;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.ejb.test.callbacks.RemoteControl;
|
import org.hibernate.ejb.test.callbacks.RemoteControl;
|
||||||
import org.hibernate.ejb.test.callbacks.Television;
|
import org.hibernate.ejb.test.callbacks.Television;
|
||||||
import org.hibernate.ejb.test.callbacks.VideoSystem;
|
import org.hibernate.ejb.test.callbacks.VideoSystem;
|
||||||
|
@ -54,7 +54,7 @@ import org.hibernate.ejb.test.inheritance.Strawberry;
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class CriteriaCompilingTest extends TestCase {
|
public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
Customer.class,
|
Customer.class,
|
||||||
|
|
|
@ -44,14 +44,14 @@ import org.hibernate.ejb.metamodel.Phone;
|
||||||
import org.hibernate.ejb.metamodel.Product;
|
import org.hibernate.ejb.metamodel.Product;
|
||||||
import org.hibernate.ejb.metamodel.ShelfLife;
|
import org.hibernate.ejb.metamodel.ShelfLife;
|
||||||
import org.hibernate.ejb.metamodel.Spouse;
|
import org.hibernate.ejb.metamodel.Spouse;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO : javadoc
|
* TODO : javadoc
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class QueryBuilderTest extends TestCase {
|
public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
@Override
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
|
|
|
@ -26,14 +26,15 @@ import javax.persistence.criteria.ParameterExpression;
|
||||||
import javax.persistence.criteria.Predicate;
|
import javax.persistence.criteria.Predicate;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
import javax.persistence.metamodel.SingularAttribute;
|
import javax.persistence.metamodel.SingularAttribute;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
|
||||||
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO : javadoc
|
* TODO : javadoc
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class BasicCriteriaUsageTest extends TestCase {
|
public class BasicCriteriaUsageTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] { Wall.class };
|
return new Class[] { Wall.class };
|
||||||
|
|
|
@ -27,13 +27,14 @@ import javax.persistence.EntityManager;
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
|
||||||
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author alan.oleary
|
* @author alan.oleary
|
||||||
*/
|
*/
|
||||||
public class ComponentCriteriaTest extends TestCase {
|
public class ComponentCriteriaTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] { Client.class };
|
return new Class[] { Client.class };
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,14 +22,14 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.metamodel;
|
package org.hibernate.ejb.metamodel;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO : javadoc
|
* TODO : javadoc
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractMetamodelSpecificTest extends TestCase {
|
public abstract class AbstractMetamodelSpecificTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
@Override
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
|
|
|
@ -25,14 +25,14 @@ package org.hibernate.ejb.metamodel;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.metamodel.EntityType;
|
import javax.persistence.metamodel.EntityType;
|
||||||
import javax.persistence.metamodel.SingularAttribute;
|
import javax.persistence.metamodel.SingularAttribute;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO : javadoc
|
* TODO : javadoc
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class EmbeddedTypeTest extends TestCase {
|
public class EmbeddedTypeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
@Override
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
// $Id$
|
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
|
@ -23,7 +22,10 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.test;
|
package org.hibernate.ejb.test;
|
||||||
import static org.hibernate.testing.TestLogger.LOG;
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.EntityManagerFactory;
|
||||||
|
import javax.persistence.Persistence;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -31,15 +33,20 @@ import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
|
||||||
import javax.persistence.Persistence;
|
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.ejb.AvailableSettings;
|
import org.hibernate.ejb.AvailableSettings;
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.testing.junit.functional.annotations.HibernateTestCase;
|
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||||
|
import org.hibernate.service.internal.ServiceRegistryImpl;
|
||||||
|
|
||||||
|
import org.hibernate.testing.AfterClassOnce;
|
||||||
|
import org.hibernate.testing.BeforeClassOnce;
|
||||||
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
|
|
||||||
|
import static org.hibernate.testing.TestLogger.LOG;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A base class for all ejb tests.
|
* A base class for all ejb tests.
|
||||||
|
@ -47,41 +54,174 @@ import org.hibernate.testing.junit.functional.annotations.HibernateTestCase;
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
public abstract class TestCase extends HibernateTestCase {
|
public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCase {
|
||||||
|
private static final Dialect dialect = Dialect.getDialect();
|
||||||
protected static EntityManagerFactory factory;
|
private static ServiceRegistryImpl serviceRegistry;
|
||||||
|
private static EntityManagerFactory factory;
|
||||||
private EntityManager em;
|
private EntityManager em;
|
||||||
private ArrayList isolatedEms = new ArrayList();
|
private ArrayList<EntityManager> isolatedEms = new ArrayList<EntityManager>();
|
||||||
|
|
||||||
|
public static Dialect getDialect() {
|
||||||
public TestCase() {
|
return dialect;
|
||||||
super();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestCase(String name) {
|
@BeforeClassOnce
|
||||||
super( name );
|
private void buildSessionFactory() throws Exception {
|
||||||
|
LOG.trace( "Building session factory" );
|
||||||
|
Ejb3Configuration ejb3Configuration = buildConfiguration();
|
||||||
|
serviceRegistry = buildServiceRegistry( ejb3Configuration.getHibernateConfiguration() );
|
||||||
|
factory = ejb3Configuration.createEntityManagerFactory( getConfig(), serviceRegistry );
|
||||||
|
afterEntityManagerFactoryBuilt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Ejb3Configuration buildConfiguration() {
|
||||||
@Override
|
Ejb3Configuration ejb3Cfg = constructConfiguration();
|
||||||
public void tearDown() throws Exception {
|
configure( ejb3Cfg.getHibernateConfiguration() );
|
||||||
super.tearDown();
|
addMappings( ejb3Cfg.getHibernateConfiguration() );
|
||||||
|
ejb3Cfg.getHibernateConfiguration().buildMappings();
|
||||||
|
afterConfigurationBuilt( ejb3Cfg.getHibernateConfiguration() );
|
||||||
|
return ejb3Cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected Ejb3Configuration constructConfiguration() {
|
||||||
protected void buildConfiguration() throws Exception {
|
Ejb3Configuration ejb3Configuration = new Ejb3Configuration();
|
||||||
Ejb3Configuration ejbconfig = new Ejb3Configuration();
|
if ( createSchema() ) {
|
||||||
HibernateTestCase.cfg = ejbconfig.getHibernateConfiguration();
|
ejb3Configuration.getHibernateConfiguration().setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||||
if ( recreateSchema() ) {
|
|
||||||
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
|
||||||
}
|
}
|
||||||
cfg.setProperty( Configuration.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
ejb3Configuration
|
||||||
|
.getHibernateConfiguration()
|
||||||
|
.setProperty( Configuration.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
||||||
|
ejb3Configuration
|
||||||
|
.getHibernateConfiguration()
|
||||||
|
.setProperty( Environment.DIALECT, getDialect().getClass().getName() );
|
||||||
|
return ejb3Configuration;
|
||||||
|
}
|
||||||
|
|
||||||
for ( String mappingFile : getMappings() ) {
|
protected void configure(Configuration hibernateConfiguration) {
|
||||||
cfg.addResource( mappingFile );
|
}
|
||||||
|
|
||||||
|
protected Map getConfig() {
|
||||||
|
Map<Object, Object> config = loadProperties();
|
||||||
|
ArrayList<Class> classes = new ArrayList<Class>();
|
||||||
|
|
||||||
|
classes.addAll( Arrays.asList( getAnnotatedClasses() ) );
|
||||||
|
config.put( AvailableSettings.LOADED_CLASSES, classes );
|
||||||
|
for ( Map.Entry<Class, String> entry : getCachedClasses().entrySet() ) {
|
||||||
|
config.put(
|
||||||
|
AvailableSettings.CLASS_CACHE_PREFIX + "." + entry.getKey().getName(),
|
||||||
|
entry.getValue()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
for ( Map.Entry<String, String> entry : getCachedCollections().entrySet() ) {
|
||||||
|
config.put(
|
||||||
|
AvailableSettings.COLLECTION_CACHE_PREFIX + "." + entry.getKey(),
|
||||||
|
entry.getValue()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ( getEjb3DD().length > 0 ) {
|
||||||
|
ArrayList<String> dds = new ArrayList<String>();
|
||||||
|
dds.addAll( Arrays.asList( getEjb3DD() ) );
|
||||||
|
config.put( AvailableSettings.XML_FILE_NAMES, dds );
|
||||||
}
|
}
|
||||||
|
|
||||||
factory = ejbconfig.createEntityManagerFactory( getConfig() );
|
addConfigOptions( config );
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addConfigOptions(Map options) {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addMappings(Configuration configuration) {
|
||||||
|
String[] mappings = getMappings();
|
||||||
|
if ( mappings != null ) {
|
||||||
|
for ( String mapping : mappings ) {
|
||||||
|
configuration.addResource(
|
||||||
|
getBaseForMappings() + mapping,
|
||||||
|
getClass().getClassLoader()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Class<?>[] annotatedClasses = getAnnotatedClasses();
|
||||||
|
// if ( annotatedClasses != null ) {
|
||||||
|
// for ( Class<?> annotatedClass : annotatedClasses ) {
|
||||||
|
// configuration.addAnnotatedClass( annotatedClass );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// String[] annotatedPackages = getAnnotatedPackages();
|
||||||
|
// if ( annotatedPackages != null ) {
|
||||||
|
// for ( String annotatedPackage : annotatedPackages ) {
|
||||||
|
// configuration.addPackage( annotatedPackage );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// String[] xmlFiles = getOrmXmlFiles();
|
||||||
|
// if ( xmlFiles != null ) {
|
||||||
|
// for ( String xmlFile : xmlFiles ) {
|
||||||
|
// configuration.addResource( xmlFile );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final String[] NO_MAPPINGS = new String[0];
|
||||||
|
|
||||||
|
protected String[] getMappings() {
|
||||||
|
return NO_MAPPINGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getBaseForMappings() {
|
||||||
|
return "org/hibernate/test/";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final Class<?>[] NO_CLASSES = new Class[0];
|
||||||
|
|
||||||
|
protected Class<?>[] getAnnotatedClasses() {
|
||||||
|
return NO_CLASSES;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String[] getAnnotatedPackages() {
|
||||||
|
return NO_MAPPINGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String[] getOrmXmlFiles() {
|
||||||
|
return NO_MAPPINGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void afterConfigurationBuilt(Configuration hibernateConfiguration) {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ServiceRegistryImpl buildServiceRegistry(Configuration configuration) {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
properties.putAll( configuration.getProperties() );
|
||||||
|
Environment.verifyProperties( properties );
|
||||||
|
ConfigurationHelper.resolvePlaceHolders( properties );
|
||||||
|
ServiceRegistryImpl serviceRegistry = new ServiceRegistryImpl( properties );
|
||||||
|
applyServices( serviceRegistry );
|
||||||
|
return serviceRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void applyServices(ServiceRegistryImpl serviceRegistry) {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void afterEntityManagerFactoryBuilt() {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean createSchema() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@AfterClassOnce
|
||||||
|
public void releaseResources() {
|
||||||
|
cleanUnclosed( this.em );
|
||||||
|
for ( EntityManager isolatedEm : isolatedEms ) {
|
||||||
|
cleanUnclosed( isolatedEm );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( factory != null ) {
|
||||||
|
factory.close();
|
||||||
|
}
|
||||||
|
if ( serviceRegistry != null ) {
|
||||||
|
serviceRegistry.destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanUnclosed(EntityManager em) {
|
private void cleanUnclosed(EntityManager em) {
|
||||||
|
@ -100,24 +240,6 @@ public abstract class TestCase extends HibernateTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void handleUnclosedResources() {
|
|
||||||
cfg = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void closeResources() {
|
|
||||||
cleanUnclosed( this.em );
|
|
||||||
for ( Object isolatedEm : isolatedEms ) {
|
|
||||||
cleanUnclosed( (EntityManager) isolatedEm );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( factory != null ) {
|
|
||||||
factory.close();
|
|
||||||
}
|
|
||||||
super.closeResources();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected EntityManager getOrCreateEntityManager() {
|
protected EntityManager getOrCreateEntityManager() {
|
||||||
if ( em == null || !em.isOpen() ) {
|
if ( em == null || !em.isOpen() ) {
|
||||||
em = factory.createEntityManager();
|
em = factory.createEntityManager();
|
||||||
|
@ -181,47 +303,4 @@ public abstract class TestCase extends HibernateTestCase {
|
||||||
props.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
props.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map getConfig() {
|
|
||||||
Map<Object, Object> config = loadProperties();
|
|
||||||
ArrayList<Class> classes = new ArrayList<Class>();
|
|
||||||
|
|
||||||
classes.addAll( Arrays.asList( getAnnotatedClasses() ) );
|
|
||||||
config.put( AvailableSettings.LOADED_CLASSES, classes );
|
|
||||||
for ( Map.Entry<Class, String> entry : getCachedClasses().entrySet() ) {
|
|
||||||
config.put(
|
|
||||||
AvailableSettings.CLASS_CACHE_PREFIX + "." + entry.getKey().getName(),
|
|
||||||
entry.getValue()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
for ( Map.Entry<String, String> entry : getCachedCollections().entrySet() ) {
|
|
||||||
config.put(
|
|
||||||
AvailableSettings.COLLECTION_CACHE_PREFIX + "." + entry.getKey(),
|
|
||||||
entry.getValue()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if ( getEjb3DD().length > 0 ) {
|
|
||||||
ArrayList<String> dds = new ArrayList<String>();
|
|
||||||
dds.addAll( Arrays.asList( getEjb3DD() ) );
|
|
||||||
config.put( AvailableSettings.XML_FILE_NAMES, dds );
|
|
||||||
}
|
|
||||||
|
|
||||||
addConfigOptions( config );
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addConfigOptions(Map options) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void runBare() throws Throwable {
|
|
||||||
if ( !appliesTo( Dialect.getDialect() ) ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
super.runBare();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean appliesTo(Dialect dialect) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -45,7 +45,7 @@ import org.hibernate.stat.Statistics;
|
||||||
/**
|
/**
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
*/
|
*/
|
||||||
public class EntityManagerTest extends TestCase {
|
public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
|
|
|
@ -1,57 +1,57 @@
|
||||||
//$Id$
|
//$Id$
|
||||||
package org.hibernate.ejb.test.association;
|
package org.hibernate.ejb.test.association;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class AssociationTest extends TestCase {
|
public class AssociationTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
public void testBidirOneToOne() throws Exception {
|
public void testBidirOneToOne() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
String id = "10";
|
String id = "10";
|
||||||
Incident i = em.find( Incident.class, id );
|
Incident i = em.find( Incident.class, id );
|
||||||
if ( i == null ) {
|
if ( i == null ) {
|
||||||
i = new Incident( id );
|
i = new Incident( id );
|
||||||
IncidentStatus ist = new IncidentStatus( id );
|
IncidentStatus ist = new IncidentStatus( id );
|
||||||
i.setIncidentStatus( ist );
|
i.setIncidentStatus( ist );
|
||||||
ist.setIncident( i );
|
ist.setIncident( i );
|
||||||
em.persist( i );
|
em.persist( i );
|
||||||
}
|
}
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.clear();
|
em.clear();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
em.remove( em.find(Incident.class, id) );
|
em.remove( em.find(Incident.class, id) );
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeAndBidirOneToOne() throws Exception {
|
public void testMergeAndBidirOneToOne() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
Oven oven = new Oven();
|
Oven oven = new Oven();
|
||||||
Kitchen kitchen = new Kitchen();
|
Kitchen kitchen = new Kitchen();
|
||||||
em.persist( oven );
|
em.persist( oven );
|
||||||
em.persist( kitchen );
|
em.persist( kitchen );
|
||||||
kitchen.setOven( oven );
|
kitchen.setOven( oven );
|
||||||
oven.setKitchen( kitchen );
|
oven.setKitchen( kitchen );
|
||||||
em.flush();
|
em.flush();
|
||||||
em.clear();
|
em.clear();
|
||||||
//oven = em.find(Oven.class, oven.getId() );
|
//oven = em.find(Oven.class, oven.getId() );
|
||||||
oven = em.merge( oven );
|
oven = em.merge( oven );
|
||||||
em.flush();
|
em.flush();
|
||||||
|
|
||||||
em.getTransaction().rollback();
|
em.getTransaction().rollback();
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[]{
|
return new Class[]{
|
||||||
Incident.class,
|
Incident.class,
|
||||||
IncidentStatus.class,
|
IncidentStatus.class,
|
||||||
Kitchen.class,
|
Kitchen.class,
|
||||||
Oven.class
|
Oven.class
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,13 @@ import java.math.BigDecimal;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.RollbackException;
|
import javax.persistence.RollbackException;
|
||||||
import javax.validation.ConstraintViolationException;
|
import javax.validation.ConstraintViolationException;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
|
||||||
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class BeanValidationTest extends TestCase {
|
public class BeanValidationTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
public void testBeanValidationIntegrationOnFlush() {
|
public void testBeanValidationIntegrationOnFlush() {
|
||||||
CupHolder ch = new CupHolder();
|
CupHolder ch = new CupHolder();
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.hibernate.Session;
|
||||||
import org.hibernate.ejb.AvailableSettings;
|
import org.hibernate.ejb.AvailableSettings;
|
||||||
import org.hibernate.ejb.HibernateEntityManager;
|
import org.hibernate.ejb.HibernateEntityManager;
|
||||||
import org.hibernate.ejb.HibernateQuery;
|
import org.hibernate.ejb.HibernateQuery;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.impl.AbstractQueryImpl;
|
import org.hibernate.impl.AbstractQueryImpl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,7 +39,7 @@ import org.hibernate.impl.AbstractQueryImpl;
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class SharedCacheModesTest extends TestCase {
|
public class SharedCacheModesTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
@Override
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] { SimpleEntity.class };
|
return new Class[] { SimpleEntity.class };
|
||||||
|
|
|
@ -3,12 +3,12 @@ package org.hibernate.ejb.test.callbacks;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class CallbackAndDirtyTest extends TestCase {
|
public class CallbackAndDirtyTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
public void testDirtyButNotDirty() throws Exception {
|
public void testDirtyButNotDirty() throws Exception {
|
||||||
EntityManager manager = getOrCreateEntityManager();
|
EntityManager manager = getOrCreateEntityManager();
|
||||||
|
|
|
@ -6,14 +6,14 @@ import java.util.List;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import org.hibernate.ejb.test.Cat;
|
import org.hibernate.ejb.test.Cat;
|
||||||
import org.hibernate.ejb.test.Kitten;
|
import org.hibernate.ejb.test.Kitten;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.testing.FailureExpected;
|
import org.hibernate.testing.FailureExpected;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class CallbacksTest extends TestCase {
|
public class CallbacksTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
public void testCallbackMethod() throws Exception {
|
public void testCallbackMethod() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
|
|
@ -1,93 +1,93 @@
|
||||||
//$Id$
|
//$Id$
|
||||||
package org.hibernate.ejb.test.cascade;
|
package org.hibernate.ejb.test.cascade;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityTransaction;
|
import javax.persistence.EntityTransaction;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Max Rydahl Andersen
|
* @author Max Rydahl Andersen
|
||||||
*/
|
*/
|
||||||
public class CascadeTest extends TestCase {
|
public class CascadeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
public void testCascade() throws Exception {
|
public void testCascade() throws Exception {
|
||||||
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
||||||
Teacher teacher = null;
|
Teacher teacher = null;
|
||||||
|
|
||||||
teacher = new Teacher();
|
teacher = new Teacher();
|
||||||
|
|
||||||
Student student = new Student();
|
Student student = new Student();
|
||||||
|
|
||||||
teacher.setFavoriteStudent(student);
|
teacher.setFavoriteStudent(student);
|
||||||
student.setFavoriteTeacher(teacher);
|
student.setFavoriteTeacher(teacher);
|
||||||
|
|
||||||
teacher.getStudents().add(student);
|
teacher.getStudents().add(student);
|
||||||
student.setPrimaryTeacher(teacher);
|
student.setPrimaryTeacher(teacher);
|
||||||
|
|
||||||
em.persist( teacher );
|
em.persist( teacher );
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
|
|
||||||
em = getOrCreateEntityManager();
|
em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
||||||
Teacher foundTeacher = (Teacher) em.createQuery( "select t from Teacher as t" ).getSingleResult();
|
Teacher foundTeacher = (Teacher) em.createQuery( "select t from Teacher as t" ).getSingleResult();
|
||||||
|
|
||||||
System.out.println(foundTeacher);
|
System.out.println(foundTeacher);
|
||||||
System.out.println(foundTeacher.getFavoriteStudent());
|
System.out.println(foundTeacher.getFavoriteStudent());
|
||||||
|
|
||||||
for (Student fstudent : foundTeacher.getStudents()) {
|
for (Student fstudent : foundTeacher.getStudents()) {
|
||||||
System.out.println(fstudent);
|
System.out.println(fstudent);
|
||||||
System.out.println(fstudent.getFavoriteTeacher());
|
System.out.println(fstudent.getFavoriteTeacher());
|
||||||
System.out.println(fstudent.getPrimaryTeacher());
|
System.out.println(fstudent.getPrimaryTeacher());
|
||||||
}
|
}
|
||||||
|
|
||||||
em.getTransaction().commit(); // here *alot* of flushes occur on an object graph that has *Zero* changes.
|
em.getTransaction().commit(); // here *alot* of flushes occur on an object graph that has *Zero* changes.
|
||||||
em.close();
|
em.close();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoCascadeAndMerge() throws Exception {
|
public void testNoCascadeAndMerge() throws Exception {
|
||||||
Song e1 = new Song();
|
Song e1 = new Song();
|
||||||
Author e2 = new Author();
|
Author e2 = new Author();
|
||||||
|
|
||||||
e1.setAuthor(e2);
|
e1.setAuthor(e2);
|
||||||
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
EntityTransaction tx = em.getTransaction();
|
EntityTransaction tx = em.getTransaction();
|
||||||
tx.begin();
|
tx.begin();
|
||||||
em.persist(e2);
|
em.persist(e2);
|
||||||
em.persist(e1);
|
em.persist(e1);
|
||||||
tx.commit();
|
tx.commit();
|
||||||
em.close();
|
em.close();
|
||||||
|
|
||||||
em = getOrCreateEntityManager();
|
em = getOrCreateEntityManager();
|
||||||
|
|
||||||
e1 = em.find(Song.class, e1.getId());
|
e1 = em.find(Song.class, e1.getId());
|
||||||
e2 = null;
|
e2 = null;
|
||||||
|
|
||||||
|
|
||||||
tx = em.getTransaction();
|
tx = em.getTransaction();
|
||||||
tx.begin();
|
tx.begin();
|
||||||
em.merge(e1);
|
em.merge(e1);
|
||||||
//em.refresh(e1);
|
//em.refresh(e1);
|
||||||
tx.commit();
|
tx.commit();
|
||||||
em.close();
|
em.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[]{
|
return new Class[]{
|
||||||
Teacher.class,
|
Teacher.class,
|
||||||
Student.class,
|
Student.class,
|
||||||
Song.class,
|
Song.class,
|
||||||
Author.class
|
Author.class
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,12 @@ import java.io.ObjectOutputStream;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityTransaction;
|
import javax.persistence.EntityTransaction;
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class DeleteOrphanTest extends TestCase {
|
public class DeleteOrphanTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
public void testDeleteOrphan() throws Exception {
|
public void testDeleteOrphan() throws Exception {
|
||||||
EntityTransaction tx;
|
EntityTransaction tx;
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,12 @@ import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class DetachAndContainsTest extends TestCase {
|
public class DetachAndContainsTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
public void testDetach() {
|
public void testDetach() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
|
|
@ -7,12 +7,12 @@ import javax.persistence.EntityTransaction;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
import org.hibernate.ejb.HibernateEntityManager;
|
import org.hibernate.ejb.HibernateEntityManager;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class FetchTest extends TestCase {
|
public class FetchTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
public void testCascadeAndFetchCollection() throws Exception {
|
public void testCascadeAndFetchCollection() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package org.hibernate.ejb.test.cascade;
|
package org.hibernate.ejb.test.cascade;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
public class FetchTest2 extends TestCase {
|
public class FetchTest2 extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
public void testProxyTransientStuff() throws Exception {
|
public void testProxyTransientStuff() throws Exception {
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.util.Date;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import javax.persistence.EntityManagerFactory;
|
||||||
import org.hibernate.ejb.HibernateEntityManager;
|
import org.hibernate.ejb.HibernateEntityManager;
|
||||||
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.ejb.test.Cat;
|
import org.hibernate.ejb.test.Cat;
|
||||||
import org.hibernate.ejb.test.Distributor;
|
import org.hibernate.ejb.test.Distributor;
|
||||||
import org.hibernate.ejb.test.Item;
|
import org.hibernate.ejb.test.Item;
|
||||||
|
@ -18,7 +19,7 @@ import org.hibernate.ejb.test.Wallet;
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class EntityManagerSerializationTest extends org.hibernate.ejb.test.TestCase {
|
public class EntityManagerSerializationTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
public void testSerialization() throws Exception {
|
public void testSerialization() throws Exception {
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
|
|
|
@ -1,60 +1,60 @@
|
||||||
//$Id$
|
//$Id$
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||||
* indicated by the @author tags or express copyright attribution
|
* indicated by the @author tags or express copyright attribution
|
||||||
* statements applied by the authors. All third-party contributions are
|
* statements applied by the authors. All third-party contributions are
|
||||||
* distributed under license by Red Hat Inc.
|
* distributed under license by Red Hat Inc.
|
||||||
*
|
*
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
* for more details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with this distribution; if not, write to:
|
* along with this distribution; if not, write to:
|
||||||
* Free Software Foundation, Inc.
|
* Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.test.emops;
|
package org.hibernate.ejb.test.emops;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class FlushModeTest extends TestCase {
|
public class FlushModeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
public void testCreateEMFlushMode() throws Exception {
|
public void testCreateEMFlushMode() throws Exception {
|
||||||
Map<String, String> properties = new HashMap<String, String>();
|
Map<String, String> properties = new HashMap<String, String>();
|
||||||
properties.put( "org.hibernate.flushMode", "manual" );
|
properties.put( "org.hibernate.flushMode", "manual" );
|
||||||
EntityManager em = createEntityManager( properties );
|
EntityManager em = createEntityManager( properties );
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
Dress dress = new Dress();
|
Dress dress = new Dress();
|
||||||
dress.name = "long dress";
|
dress.name = "long dress";
|
||||||
em.persist( dress );
|
em.persist( dress );
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
|
|
||||||
em.clear();
|
em.clear();
|
||||||
|
|
||||||
assertNull( em.find( Dress.class, dress.name ) );
|
assertNull( em.find( Dress.class, dress.name ) );
|
||||||
|
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
Race.class,
|
Race.class,
|
||||||
Competitor.class,
|
Competitor.class,
|
||||||
Dress.class
|
Dress.class
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,13 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
|
||||||
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class FlushTest extends TestCase {
|
public class FlushTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
private static Set<String> names= new HashSet<String>();
|
private static Set<String> names= new HashSet<String>();
|
||||||
static {
|
static {
|
||||||
names.add("Toonses");
|
names.add("Toonses");
|
||||||
|
|
|
@ -1,45 +1,45 @@
|
||||||
//$Id$
|
//$Id$
|
||||||
package org.hibernate.ejb.test.emops;
|
package org.hibernate.ejb.test.emops;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class GetReferenceTest extends TestCase {
|
public class GetReferenceTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
public void testWrongIdType() throws Exception {
|
public void testWrongIdType() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
try {
|
try {
|
||||||
Competitor c = em.getReference( Competitor.class, new String("30") );
|
Competitor c = em.getReference( Competitor.class, new String("30") );
|
||||||
fail("Expected IllegalArgumentException");
|
fail("Expected IllegalArgumentException");
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
//success
|
//success
|
||||||
}
|
}
|
||||||
catch ( Exception e ) {
|
catch ( Exception e ) {
|
||||||
fail("Wrong exception: " + e );
|
fail("Wrong exception: " + e );
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Mail c = em.getReference( Mail.class, 1 );
|
Mail c = em.getReference( Mail.class, 1 );
|
||||||
fail("Expected IllegalArgumentException");
|
fail("Expected IllegalArgumentException");
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
//success
|
//success
|
||||||
}
|
}
|
||||||
catch ( Exception e ) {
|
catch ( Exception e ) {
|
||||||
fail("Wrong exception: " + e );
|
fail("Wrong exception: " + e );
|
||||||
}
|
}
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
Competitor.class,
|
Competitor.class,
|
||||||
Race.class,
|
Race.class,
|
||||||
Mail.class
|
Mail.class
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,185 +1,185 @@
|
||||||
//$Id$
|
//$Id$
|
||||||
package org.hibernate.ejb.test.emops;
|
package org.hibernate.ejb.test.emops;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class MergeTest extends TestCase {
|
public class MergeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
public void testMergeWithIndexColumn() {
|
public void testMergeWithIndexColumn() {
|
||||||
Race race = new Race();
|
Race race = new Race();
|
||||||
race.competitors.add( new Competitor( "Name" ) );
|
race.competitors.add( new Competitor( "Name" ) );
|
||||||
race.competitors.add( new Competitor() );
|
race.competitors.add( new Competitor() );
|
||||||
race.competitors.add( new Competitor() );
|
race.competitors.add( new Competitor() );
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
em.persist( race );
|
em.persist( race );
|
||||||
em.flush();
|
em.flush();
|
||||||
em.clear();
|
em.clear();
|
||||||
race.competitors.add( new Competitor() );
|
race.competitors.add( new Competitor() );
|
||||||
race.competitors.remove( 2 );
|
race.competitors.remove( 2 );
|
||||||
race.competitors.remove( 1 );
|
race.competitors.remove( 1 );
|
||||||
race.competitors.get( 0 ).setName( "Name2" );
|
race.competitors.get( 0 ).setName( "Name2" );
|
||||||
race = em.merge( race );
|
race = em.merge( race );
|
||||||
em.flush();
|
em.flush();
|
||||||
em.clear();
|
em.clear();
|
||||||
race = em.find( Race.class, race.id );
|
race = em.find( Race.class, race.id );
|
||||||
assertEquals( 2, race.competitors.size() );
|
assertEquals( 2, race.competitors.size() );
|
||||||
assertEquals( "Name2", race.competitors.get( 0 ).getName() );
|
assertEquals( "Name2", race.competitors.get( 0 ).getName() );
|
||||||
em.getTransaction().rollback();
|
em.getTransaction().rollback();
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeManyToMany() {
|
public void testMergeManyToMany() {
|
||||||
Competition competition = new Competition();
|
Competition competition = new Competition();
|
||||||
competition.getCompetitors().add( new Competitor( "Name" ) );
|
competition.getCompetitors().add( new Competitor( "Name" ) );
|
||||||
competition.getCompetitors().add( new Competitor() );
|
competition.getCompetitors().add( new Competitor() );
|
||||||
competition.getCompetitors().add( new Competitor() );
|
competition.getCompetitors().add( new Competitor() );
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
em.persist( competition );
|
em.persist( competition );
|
||||||
em.flush();
|
em.flush();
|
||||||
em.clear();
|
em.clear();
|
||||||
competition.getCompetitors().add( new Competitor() );
|
competition.getCompetitors().add( new Competitor() );
|
||||||
competition.getCompetitors().remove( 2 );
|
competition.getCompetitors().remove( 2 );
|
||||||
competition.getCompetitors().remove( 1 );
|
competition.getCompetitors().remove( 1 );
|
||||||
competition.getCompetitors().get( 0 ).setName( "Name2" );
|
competition.getCompetitors().get( 0 ).setName( "Name2" );
|
||||||
competition = em.merge( competition );
|
competition = em.merge( competition );
|
||||||
em.flush();
|
em.flush();
|
||||||
em.clear();
|
em.clear();
|
||||||
competition = em.find( Competition.class, competition.getId() );
|
competition = em.find( Competition.class, competition.getId() );
|
||||||
assertEquals( 2, competition.getCompetitors().size() );
|
assertEquals( 2, competition.getCompetitors().size() );
|
||||||
// we cannot assume that the order in the list is maintained - HHH-4516
|
// we cannot assume that the order in the list is maintained - HHH-4516
|
||||||
String changedCompetitorName;
|
String changedCompetitorName;
|
||||||
if ( competition.getCompetitors().get( 0 ).getName() != null ) {
|
if ( competition.getCompetitors().get( 0 ).getName() != null ) {
|
||||||
changedCompetitorName = competition.getCompetitors().get( 0 ).getName();
|
changedCompetitorName = competition.getCompetitors().get( 0 ).getName();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
changedCompetitorName = competition.getCompetitors().get( 1 ).getName();
|
changedCompetitorName = competition.getCompetitors().get( 1 ).getName();
|
||||||
}
|
}
|
||||||
assertEquals( "Name2", changedCompetitorName );
|
assertEquals( "Name2", changedCompetitorName );
|
||||||
em.getTransaction().rollback();
|
em.getTransaction().rollback();
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeManyToManyWithDeference() {
|
public void testMergeManyToManyWithDeference() {
|
||||||
Competition competition = new Competition();
|
Competition competition = new Competition();
|
||||||
competition.getCompetitors().add( new Competitor( "Name" ) );
|
competition.getCompetitors().add( new Competitor( "Name" ) );
|
||||||
competition.getCompetitors().add( new Competitor() );
|
competition.getCompetitors().add( new Competitor() );
|
||||||
competition.getCompetitors().add( new Competitor() );
|
competition.getCompetitors().add( new Competitor() );
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
em.persist( competition );
|
em.persist( competition );
|
||||||
em.flush();
|
em.flush();
|
||||||
em.clear();
|
em.clear();
|
||||||
List<Competitor> newComp = new ArrayList<Competitor>();
|
List<Competitor> newComp = new ArrayList<Competitor>();
|
||||||
newComp.add( competition.getCompetitors().get( 0 ) );
|
newComp.add( competition.getCompetitors().get( 0 ) );
|
||||||
newComp.add( new Competitor() );
|
newComp.add( new Competitor() );
|
||||||
newComp.get( 0 ).setName( "Name2" );
|
newComp.get( 0 ).setName( "Name2" );
|
||||||
competition.setCompetitors( newComp );
|
competition.setCompetitors( newComp );
|
||||||
competition = em.merge( competition );
|
competition = em.merge( competition );
|
||||||
em.flush();
|
em.flush();
|
||||||
em.clear();
|
em.clear();
|
||||||
competition = em.find( Competition.class, competition.getId() );
|
competition = em.find( Competition.class, competition.getId() );
|
||||||
assertEquals( 2, competition.getCompetitors().size() );
|
assertEquals( 2, competition.getCompetitors().size() );
|
||||||
// we cannot assume that the order in the list is maintained - HHH-4516
|
// we cannot assume that the order in the list is maintained - HHH-4516
|
||||||
String changedCompetitorName;
|
String changedCompetitorName;
|
||||||
if ( competition.getCompetitors().get( 0 ).getName() != null ) {
|
if ( competition.getCompetitors().get( 0 ).getName() != null ) {
|
||||||
changedCompetitorName = competition.getCompetitors().get( 0 ).getName();
|
changedCompetitorName = competition.getCompetitors().get( 0 ).getName();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
changedCompetitorName = competition.getCompetitors().get( 1 ).getName();
|
changedCompetitorName = competition.getCompetitors().get( 1 ).getName();
|
||||||
}
|
}
|
||||||
assertEquals( "Name2", changedCompetitorName );
|
assertEquals( "Name2", changedCompetitorName );
|
||||||
em.getTransaction().rollback();
|
em.getTransaction().rollback();
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRemoveAndMerge() {
|
public void testRemoveAndMerge() {
|
||||||
Race race = new Race();
|
Race race = new Race();
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
em.persist( race );
|
em.persist( race );
|
||||||
em.flush();
|
em.flush();
|
||||||
em.clear();
|
em.clear();
|
||||||
race = em.find( Race.class, race.id );
|
race = em.find( Race.class, race.id );
|
||||||
em.remove( race );
|
em.remove( race );
|
||||||
try {
|
try {
|
||||||
race = em.merge( race );
|
race = em.merge( race );
|
||||||
em.flush();
|
em.flush();
|
||||||
fail( "Should raise an IllegalArgumentException" );
|
fail( "Should raise an IllegalArgumentException" );
|
||||||
}
|
}
|
||||||
catch ( IllegalArgumentException e ) {
|
catch ( IllegalArgumentException e ) {
|
||||||
//all good
|
//all good
|
||||||
}
|
}
|
||||||
catch ( Exception e ) {
|
catch ( Exception e ) {
|
||||||
fail( "Should raise an IllegalArgumentException" );
|
fail( "Should raise an IllegalArgumentException" );
|
||||||
}
|
}
|
||||||
em.getTransaction().rollback();
|
em.getTransaction().rollback();
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConcurrentMerge() {
|
public void testConcurrentMerge() {
|
||||||
Race race = new Race();
|
Race race = new Race();
|
||||||
race.name = "Derby";
|
race.name = "Derby";
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
em.persist( race );
|
em.persist( race );
|
||||||
em.flush();
|
em.flush();
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.close();
|
em.close();
|
||||||
|
|
||||||
race.name = "Magnicourt";
|
race.name = "Magnicourt";
|
||||||
|
|
||||||
em = getOrCreateEntityManager();
|
em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
Race race2 = em.find( Race.class, race.id );
|
Race race2 = em.find( Race.class, race.id );
|
||||||
race2.name = "Mans";
|
race2.name = "Mans";
|
||||||
|
|
||||||
race = em.merge( race );
|
race = em.merge( race );
|
||||||
em.flush();
|
em.flush();
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.close();
|
em.close();
|
||||||
|
|
||||||
em = getOrCreateEntityManager();
|
em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
race2 = em.find( Race.class, race.id );
|
race2 = em.find( Race.class, race.id );
|
||||||
assertEquals( "Last commit win in merge", "Magnicourt", race2.name );
|
assertEquals( "Last commit win in merge", "Magnicourt", race2.name );
|
||||||
|
|
||||||
em.remove( race2 );
|
em.remove( race2 );
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeUnidirectionalOneToMany() throws Exception {
|
public void testMergeUnidirectionalOneToMany() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
Empire roman = new Empire();
|
Empire roman = new Empire();
|
||||||
em.persist( roman );
|
em.persist( roman );
|
||||||
em.flush();
|
em.flush();
|
||||||
em.clear();
|
em.clear();
|
||||||
roman = em.find( Empire.class, roman.getId() );
|
roman = em.find( Empire.class, roman.getId() );
|
||||||
Colony gaule = new Colony();
|
Colony gaule = new Colony();
|
||||||
roman.getColonies().add( gaule );
|
roman.getColonies().add( gaule );
|
||||||
em.merge( roman );
|
em.merge( roman );
|
||||||
em.flush();
|
em.flush();
|
||||||
em.clear();
|
em.clear();
|
||||||
roman = em.find( Empire.class, roman.getId() );
|
roman = em.find( Empire.class, roman.getId() );
|
||||||
assertEquals( 1, roman.getColonies().size() );
|
assertEquals( 1, roman.getColonies().size() );
|
||||||
em.getTransaction().rollback();
|
em.getTransaction().rollback();
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
Race.class,
|
Race.class,
|
||||||
Competitor.class,
|
Competitor.class,
|
||||||
Competition.class,
|
Competition.class,
|
||||||
Empire.class,
|
Empire.class,
|
||||||
Colony.class
|
Colony.class
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,37 +1,37 @@
|
||||||
//$Id$
|
//$Id$
|
||||||
package org.hibernate.ejb.test.emops;
|
package org.hibernate.ejb.test.emops;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class RefreshTest extends TestCase {
|
public class RefreshTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
public void testRefreshNonManaged() throws Exception {
|
public void testRefreshNonManaged() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
Race race = new Race();
|
Race race = new Race();
|
||||||
em.persist( race );
|
em.persist( race );
|
||||||
em.flush();
|
em.flush();
|
||||||
em.clear();
|
em.clear();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
em.refresh( race );
|
em.refresh( race );
|
||||||
fail("Refresh should fail on a non managed entity");
|
fail("Refresh should fail on a non managed entity");
|
||||||
}
|
}
|
||||||
catch( IllegalArgumentException e) {
|
catch( IllegalArgumentException e) {
|
||||||
//success
|
//success
|
||||||
}
|
}
|
||||||
|
|
||||||
em.getTransaction().rollback();
|
em.getTransaction().rollback();
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
Race.class,
|
Race.class,
|
||||||
Competitor.class
|
Competitor.class
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,13 @@ import static org.hibernate.testing.TestLogger.LOG;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.OptimisticLockException;
|
import javax.persistence.OptimisticLockException;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
|
||||||
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class RemoveTest extends TestCase {
|
public class RemoveTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
public void testRemove() {
|
public void testRemove() {
|
||||||
Race race = new Race();
|
Race race = new Race();
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
package org.hibernate.ejb.test.emops.cascade;
|
package org.hibernate.ejb.test.emops.cascade;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.stat.Statistics;
|
import org.hibernate.stat.Statistics;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class CascadePersistTest extends TestCase {
|
public class CascadePersistTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
public void testLazyCollectionsStayLazyOnPersist() throws Exception {
|
public void testLazyCollectionsStayLazyOnPersist() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
|
|
@ -7,14 +7,14 @@ import javax.persistence.EntityNotFoundException;
|
||||||
import javax.persistence.OptimisticLockException;
|
import javax.persistence.OptimisticLockException;
|
||||||
import javax.persistence.PersistenceException;
|
import javax.persistence.PersistenceException;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.exception.ConstraintViolationException;
|
import org.hibernate.exception.ConstraintViolationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class ExceptionTest extends TestCase {
|
public class ExceptionTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
public void testOptimisticLockingException() throws Exception {
|
public void testOptimisticLockingException() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
|
|
@ -1,39 +1,39 @@
|
||||||
//$Id$
|
//$Id$
|
||||||
package org.hibernate.ejb.test.inheritance;
|
package org.hibernate.ejb.test.inheritance;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class InheritanceTest extends TestCase {
|
public class InheritanceTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
public void testFind() throws Exception {
|
public void testFind() throws Exception {
|
||||||
EntityManager firstSession = getOrCreateEntityManager( );
|
EntityManager firstSession = getOrCreateEntityManager( );
|
||||||
Strawberry u = new Strawberry();
|
Strawberry u = new Strawberry();
|
||||||
u.setSize( 12l );
|
u.setSize( 12l );
|
||||||
firstSession.getTransaction().begin();
|
firstSession.getTransaction().begin();
|
||||||
firstSession.persist(u);
|
firstSession.persist(u);
|
||||||
firstSession.getTransaction().commit();
|
firstSession.getTransaction().commit();
|
||||||
Long newId = u.getId();
|
Long newId = u.getId();
|
||||||
firstSession.clear();
|
firstSession.clear();
|
||||||
|
|
||||||
firstSession.getTransaction().begin();
|
firstSession.getTransaction().begin();
|
||||||
// 1.
|
// 1.
|
||||||
Strawberry result1 = firstSession.find(Strawberry.class, newId);
|
Strawberry result1 = firstSession.find(Strawberry.class, newId);
|
||||||
assertNotNull( result1 );
|
assertNotNull( result1 );
|
||||||
|
|
||||||
// 2.
|
// 2.
|
||||||
Strawberry result2 = (Strawberry) firstSession.find(Fruit.class, newId);
|
Strawberry result2 = (Strawberry) firstSession.find(Fruit.class, newId);
|
||||||
System.out.println("2. result is:" + result2);
|
System.out.println("2. result is:" + result2);
|
||||||
|
|
||||||
firstSession.getTransaction().commit();
|
firstSession.getTransaction().commit();
|
||||||
firstSession.close();
|
firstSession.close();
|
||||||
}
|
}
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
Fruit.class,
|
Fruit.class,
|
||||||
Strawberry.class
|
Strawberry.class
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,49 @@
|
||||||
//$Id$
|
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.lob;
|
package org.hibernate.ejb.test.lob;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
|
||||||
|
import org.hibernate.testing.DialectChecks;
|
||||||
|
import org.hibernate.testing.RequiresDialectFeature;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class BlobTest extends TestCase {
|
@RequiresDialectFeature( DialectChecks.SupportsExpectedLobUsagePattern.class )
|
||||||
|
public class BlobTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
public void testBlobSerialization() throws Exception {
|
public void testBlobSerialization() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
@ -39,14 +69,7 @@ public class BlobTest extends TestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean appliesTo(Dialect dialect) {
|
|
||||||
return dialect.supportsExpectedLobUsagePattern();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[]{
|
return new Class[] { ImageReader.class };
|
||||||
ImageReader.class
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,12 +17,12 @@ import javax.persistence.QueryTimeoutException;
|
||||||
import org.hibernate.dialect.HSQLDialect;
|
import org.hibernate.dialect.HSQLDialect;
|
||||||
import org.hibernate.dialect.Oracle10gDialect;
|
import org.hibernate.dialect.Oracle10gDialect;
|
||||||
import org.hibernate.ejb.AvailableSettings;
|
import org.hibernate.ejb.AvailableSettings;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class LockTest extends TestCase {
|
public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
public void testFindWithTimeoutHint() {
|
public void testFindWithTimeoutHint() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.hibernate.LockMode;
|
||||||
import org.hibernate.cfg.AnnotationConfiguration;
|
import org.hibernate.cfg.AnnotationConfiguration;
|
||||||
import org.hibernate.ejb.AvailableSettings;
|
import org.hibernate.ejb.AvailableSettings;
|
||||||
import org.hibernate.ejb.QueryImpl;
|
import org.hibernate.ejb.QueryImpl;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.impl.SessionImpl;
|
import org.hibernate.impl.SessionImpl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,7 +37,7 @@ import org.hibernate.impl.SessionImpl;
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class QueryLockingTest extends TestCase {
|
public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
protected Class<?>[] getAnnotatedClasses() {
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package org.hibernate.ejb.test.mapping;
|
package org.hibernate.ejb.test.mapping;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class QuotingTest extends TestCase {
|
public class QuotingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
public void testQuote() {
|
public void testQuote() {
|
||||||
// the configuration was failing
|
// the configuration was failing
|
||||||
|
|
|
@ -38,13 +38,13 @@ import javax.persistence.metamodel.SingularAttribute;
|
||||||
import javax.persistence.metamodel.Type;
|
import javax.persistence.metamodel.Type;
|
||||||
import org.hibernate.cfg.AnnotationConfiguration;
|
import org.hibernate.cfg.AnnotationConfiguration;
|
||||||
import org.hibernate.ejb.metamodel.MetamodelImpl;
|
import org.hibernate.ejb.metamodel.MetamodelImpl;
|
||||||
import org.hibernate.ejb.test.TestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.engine.SessionFactoryImplementor;
|
import org.hibernate.engine.SessionFactoryImplementor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class MetadataTest extends TestCase {
|
public class MetadataTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
public void testBaseOfService() throws Exception {
|
public void testBaseOfService() throws Exception {
|
||||||
EntityManagerFactory emf = factory;
|
EntityManagerFactory emf = factory;
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue