diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/javassist/BulkAccessor.java b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/javassist/BulkAccessor.java index 1c286eadea..21fc2cd5b8 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/javassist/BulkAccessor.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/javassist/BulkAccessor.java @@ -29,7 +29,7 @@ import java.io.Serializable; * A JavaBean bulk accessor, which provides methods capable of getting/setting multiple properties * of a JavaBean at once. * - * IMPORTANT NOTE!!! Apparently the order of the methods here is important as I think BulkAccessorFactory + * IMPORTANT NOTE!!! Apparently the order of the methods here is important as I think {@link BulkAccessorFactory} * makes use of that information in terms of accessing the constructor. Anyway, when I tried to re-arrange them * the BulkAccessor creation failed and tests started to fail. * diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AbstractPropertyHolder.java b/hibernate-core/src/main/java/org/hibernate/cfg/AbstractPropertyHolder.java index bccd2d9a36..f7898b2cb8 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AbstractPropertyHolder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AbstractPropertyHolder.java @@ -72,7 +72,7 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { @Override public boolean isInIdClass() { - return isInIdClass != null ? isInIdClass : parent != null ? parent.isInIdClass() : false; + return isInIdClass != null ? isInIdClass : parent != null && parent.isInIdClass(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/property/BackrefPropertyAccessor.java b/hibernate-core/src/main/java/org/hibernate/property/BackrefPropertyAccessor.java index d4872b15b8..f819ccf9ef 100755 --- a/hibernate-core/src/main/java/org/hibernate/property/BackrefPropertyAccessor.java +++ b/hibernate-core/src/main/java/org/hibernate/property/BackrefPropertyAccessor.java @@ -55,6 +55,7 @@ public class BackrefPropertyAccessor implements PropertyAccessor { * we don't know the value of the back reference */ public static final Serializable UNKNOWN = new Serializable() { + @Override public String toString() { return ""; } @@ -78,16 +79,12 @@ public class BackrefPropertyAccessor implements PropertyAccessor { this.getter = new BackrefGetter(); } - /** - * {@inheritDoc} - */ + @Override public Setter getSetter(Class theClass, String propertyName) { return setter; } - /** - * {@inheritDoc} - */ + @Override public Getter getGetter(Class theClass, String propertyName) { return getter; } @@ -98,23 +95,17 @@ public class BackrefPropertyAccessor implements PropertyAccessor { */ public static final class BackrefSetter implements Setter { - /** - * {@inheritDoc} - */ + @Override public Method getMethod() { return null; } - /** - * {@inheritDoc} - */ + @Override public String getMethodName() { return null; } - /** - * {@inheritDoc} - */ + @Override public void set(Object target, Object value, SessionFactoryImplementor factory) { // this page intentionally left blank :) } @@ -127,9 +118,7 @@ public class BackrefPropertyAccessor implements PropertyAccessor { */ public class BackrefGetter implements Getter { - /** - * {@inheritDoc} - */ + @Override public Object getForInsert(Object target, Map mergeMap, SessionImplementor session) { if ( session == null ) { return UNKNOWN; @@ -139,37 +128,27 @@ public class BackrefPropertyAccessor implements PropertyAccessor { } } - /** - * {@inheritDoc} - */ + @Override public Member getMember() { return null; } - /** - * {@inheritDoc} - */ + @Override public Object get(Object target) { return UNKNOWN; } - /** - * {@inheritDoc} - */ + @Override public Method getMethod() { return null; } - /** - * {@inheritDoc} - */ + @Override public String getMethodName() { return null; } - /** - * {@inheritDoc} - */ + @Override public Class getReturnType() { return Object.class; } diff --git a/hibernate-core/src/main/java/org/hibernate/property/BasicPropertyAccessor.java b/hibernate-core/src/main/java/org/hibernate/property/BasicPropertyAccessor.java index 15523c2437..383391a04c 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/BasicPropertyAccessor.java +++ b/hibernate-core/src/main/java/org/hibernate/property/BasicPropertyAccessor.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.property; + import java.beans.Introspector; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Member; @@ -46,33 +47,37 @@ import org.hibernate.internal.util.ReflectHelper; */ public class BasicPropertyAccessor implements PropertyAccessor { - private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, BasicPropertyAccessor.class.getName()); + private static final CoreMessageLogger LOG = Logger.getMessageLogger( + CoreMessageLogger.class, + BasicPropertyAccessor.class.getName() + ); public static final class BasicSetter implements Setter { - private Class clazz; + private final Class clazz; private final transient Method method; private final String propertyName; private BasicSetter(Class clazz, Method method, String propertyName) { - this.clazz=clazz; - this.method=method; - this.propertyName=propertyName; + this.clazz = clazz; + this.method = method; + this.propertyName = propertyName; } + @Override public void set(Object target, Object value, SessionFactoryImplementor factory) - throws HibernateException { + throws HibernateException { try { method.invoke( target, value ); } - catch (NullPointerException npe) { - if ( value==null && method.getParameterTypes()[0].isPrimitive() ) { + catch ( NullPointerException npe ) { + if ( value == null && method.getParameterTypes()[0].isPrimitive() ) { throw new PropertyAccessException( npe, "Null value was assigned to a property of primitive type", true, clazz, propertyName - ); + ); } else { throw new PropertyAccessException( @@ -81,66 +86,71 @@ public class BasicPropertyAccessor implements PropertyAccessor { true, clazz, propertyName - ); + ); } } - catch (InvocationTargetException ite) { + catch ( InvocationTargetException ite ) { throw new PropertyAccessException( ite, "Exception occurred inside", true, clazz, propertyName - ); + ); } - catch (IllegalAccessException iae) { + catch ( IllegalAccessException iae ) { throw new PropertyAccessException( iae, "IllegalAccessException occurred while calling", true, clazz, propertyName - ); + ); //cannot occur } - catch (IllegalArgumentException iae) { - if ( value==null && method.getParameterTypes()[0].isPrimitive() ) { + catch ( IllegalArgumentException iae ) { + if ( value == null && method.getParameterTypes()[0].isPrimitive() ) { throw new PropertyAccessException( iae, "Null value was assigned to a property of primitive type", true, clazz, propertyName - ); + ); } else { - LOG.illegalPropertySetterArgument(clazz.getName(), propertyName); - LOG.expectedType(method.getParameterTypes()[0].getName(), value == null ? null : value.getClass().getName()); + LOG.illegalPropertySetterArgument( clazz.getName(), propertyName ); + LOG.expectedType( + method.getParameterTypes()[0].getName(), + value == null ? null : value.getClass().getName() + ); throw new PropertyAccessException( iae, "IllegalArgumentException occurred while calling", true, clazz, propertyName - ); + ); } } } + @Override public Method getMethod() { return method; } + @Override public String getMethodName() { return method.getName(); } Object readResolve() { - return createSetter(clazz, propertyName); + return createSetter( clazz, propertyName ); } @Override - public String toString() { + public String toString() { return "BasicSetter(" + clazz.getName() + '.' + propertyName + ')'; } } @@ -151,130 +161,122 @@ public class BasicPropertyAccessor implements PropertyAccessor { private final String propertyName; private BasicGetter(Class clazz, Method method, String propertyName) { - this.clazz=clazz; - this.method=method; - this.propertyName=propertyName; + this.clazz = clazz; + this.method = method; + this.propertyName = propertyName; } - /** - * {@inheritDoc} - */ + @Override public Object get(Object target) throws HibernateException { try { return method.invoke( target, (Object[]) null ); } - catch (InvocationTargetException ite) { + catch ( InvocationTargetException ite ) { throw new PropertyAccessException( ite, "Exception occurred inside", false, clazz, propertyName - ); + ); } - catch (IllegalAccessException iae) { + catch ( IllegalAccessException iae ) { throw new PropertyAccessException( iae, "IllegalAccessException occurred while calling", false, clazz, propertyName - ); + ); //cannot occur } - catch (IllegalArgumentException iae) { - LOG.illegalPropertyGetterArgument(clazz.getName(), propertyName); + catch ( IllegalArgumentException iae ) { + LOG.illegalPropertyGetterArgument( clazz.getName(), propertyName ); throw new PropertyAccessException( iae, "IllegalArgumentException occurred calling", false, clazz, propertyName - ); + ); } } - /** - * {@inheritDoc} - */ + @Override public Object getForInsert(Object target, Map mergeMap, SessionImplementor session) { return get( target ); } - /** - * {@inheritDoc} - */ + @Override public Class getReturnType() { return method.getReturnType(); } - /** - * {@inheritDoc} - */ + @Override public Member getMember() { return method; } - /** - * {@inheritDoc} - */ + @Override public Method getMethod() { return method; } - /** - * {@inheritDoc} - */ + @Override public String getMethodName() { return method.getName(); } @Override - public String toString() { + public String toString() { return "BasicGetter(" + clazz.getName() + '.' + propertyName + ')'; } Object readResolve() { - return createGetter(clazz, propertyName); + return createGetter( clazz, propertyName ); } } public Setter getSetter(Class theClass, String propertyName) - throws PropertyNotFoundException { - return createSetter(theClass, propertyName); + throws PropertyNotFoundException { + return createSetter( theClass, propertyName ); } private static Setter createSetter(Class theClass, String propertyName) - throws PropertyNotFoundException { - BasicSetter result = getSetterOrNull(theClass, propertyName); - if (result==null) { + throws PropertyNotFoundException { + BasicSetter result = getSetterOrNull( theClass, propertyName ); + if ( result == null ) { throw new PropertyNotFoundException( "Could not find a setter for property " + - propertyName + - " in class " + - theClass.getName() - ); + propertyName + + " in class " + + theClass.getName() + ); } return result; } private static BasicSetter getSetterOrNull(Class theClass, String propertyName) { - if (theClass==Object.class || theClass==null) return null; + if ( theClass == Object.class || theClass == null ) { + return null; + } - Method method = setterMethod(theClass, propertyName); + Method method = setterMethod( theClass, propertyName ); - if (method!=null) { - if ( !ReflectHelper.isPublic(theClass, method) ) method.setAccessible(true); - return new BasicSetter(theClass, method, propertyName); + if ( method != null ) { + if ( !ReflectHelper.isPublic( theClass, method ) ) { + method.setAccessible( true ); + } + return new BasicSetter( theClass, method, propertyName ); } else { BasicSetter setter = getSetterOrNull( theClass.getSuperclass(), propertyName ); - if (setter==null) { + if ( setter == null ) { Class[] interfaces = theClass.getInterfaces(); - for ( int i=0; setter==null && i * Here we always return null */ + @Override public Object get(Object target) throws HibernateException { return null; } - /** - * {@inheritDoc} - */ + @Override public Object getForInsert(Object target, Map map, SessionImplementor arg1) throws HibernateException { return null; } - /** - * {@inheritDoc} - */ + @Override public Class getReturnType() { return Object.class; } - /** - * {@inheritDoc} - */ + @Override public Member getMember() { return null; } - /** - * {@inheritDoc} - */ + @Override public String getMethodName() { return null; } - /** - * {@inheritDoc} - */ + @Override public Method getMethod() { return null; } @@ -105,23 +90,17 @@ public class NoopAccessor implements PropertyAccessor { * A Setter which will just do nothing. */ private static class NoopSetter implements Setter { - /** - * {@inheritDoc} - */ + @Override public void set(Object target, Object value, SessionFactoryImplementor arg2) { // nothing to do } - /** - * {@inheritDoc} - */ + @Override public String getMethodName() { return null; } - /** - * {@inheritDoc} - */ + @Override public Method getMethod() { return null; } diff --git a/hibernate-core/src/test/java/org/hibernate/test/instrument/cases/AbstractExecutable.java b/hibernate-core/src/test/java/org/hibernate/test/instrument/cases/AbstractExecutable.java index 6d228212d2..396fbe7166 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/instrument/cases/AbstractExecutable.java +++ b/hibernate-core/src/test/java/org/hibernate/test/instrument/cases/AbstractExecutable.java @@ -1,6 +1,9 @@ package org.hibernate.test.instrument.cases; import org.hibernate.SessionFactory; +import org.hibernate.boot.registry.BootstrapServiceRegistry; +import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.metamodel.MetadataSources; @@ -17,8 +20,22 @@ public abstract class AbstractExecutable implements Executable { private SessionFactory factory; @Override public final void prepare() { + prepare( null ); + } + + @Override + public final void prepare(ClassLoader instrumentedClassLoader) { Configuration cfg = new Configuration().setProperty( Environment.HBM2DDL_AUTO, "create-drop" ); - serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() ); + BootstrapServiceRegistryBuilder bootstrapServiceRegistryBuilder = new BootstrapServiceRegistryBuilder(); + if ( instrumentedClassLoader != null ) // old metamodel case + { + bootstrapServiceRegistryBuilder.with( instrumentedClassLoader ); + } + BootstrapServiceRegistry bootstrapServiceRegistry = bootstrapServiceRegistryBuilder.build(); + + StandardServiceRegistryBuilder standardServiceRegistryBuilder = new StandardServiceRegistryBuilder(bootstrapServiceRegistry); + serviceRegistry = standardServiceRegistryBuilder.applySettings( cfg.getProperties() ).build(); + String[] resources = getResources(); if( BaseUnitTestCase.isMetadataUsed()){ MetadataSources metadataSources = new MetadataSources( serviceRegistry ); @@ -34,7 +51,8 @@ public abstract class AbstractExecutable implements Executable { } } - @Override + + @Override public final void complete() { try { cleanup(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/instrument/cases/Executable.java b/hibernate-core/src/test/java/org/hibernate/test/instrument/cases/Executable.java index cc322ef574..4ed64b8e74 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/instrument/cases/Executable.java +++ b/hibernate-core/src/test/java/org/hibernate/test/instrument/cases/Executable.java @@ -1,11 +1,21 @@ package org.hibernate.test.instrument.cases; - /** * @author Steve Ebersole */ public interface Executable { - public void prepare(); - public void execute() throws Exception; - public void complete(); + void prepare(); + + /** + * The reason that we need this method in the metamodel branch is because in this branch, + * we use {@link org.hibernate.boot.registry.classloading.spi.ClassLoaderService} to load entity classes + * (well, every classes), and by default, this service uses default hibernate classloader first, then + * it will bypass the instrument classloader, so here we have to explicitly provide this classloader to the + * {@link org.hibernate.boot.registry.classloading.spi.ClassLoaderService}. + * + * @param instrumentedClassLoader + */ + void prepare(ClassLoader instrumentedClassLoader); + void execute() throws Exception; + void complete(); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/instrument/cases/TestLazyExecutable.java b/hibernate-core/src/test/java/org/hibernate/test/instrument/cases/TestLazyExecutable.java index d8b95ba5c1..2864a9bfe5 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/instrument/cases/TestLazyExecutable.java +++ b/hibernate-core/src/test/java/org/hibernate/test/instrument/cases/TestLazyExecutable.java @@ -1,4 +1,5 @@ package org.hibernate.test.instrument.cases; + import junit.framework.TestCase; import org.hibernate.CacheMode; @@ -15,6 +16,7 @@ import org.hibernate.test.instrument.domain.Owner; * @author Steve Ebersole */ public class TestLazyExecutable extends AbstractExecutable { + @Override public void execute() { // The following block is repeated 100 times to reproduce HHH-2627. // Without the fix, Oracle will run out of cursors using 10g with @@ -22,183 +24,183 @@ public class TestLazyExecutable extends AbstractExecutable { // The number of loops may need to be adjusted depending on the how // Oracle is configured. // Note: The block is not indented to avoid a lot of irrelevant differences. - for ( int i=0; i<100; i++ ) { + for ( int i = 0; i < 100; i++ ) { - SessionFactory factory = getFactory(); - Session s = factory.openSession(); - Transaction t = s.beginTransaction(); - Owner o = new Owner(); - Document doc = new Document(); - Folder fol = new Folder(); - o.setName("gavin"); - doc.setName("Hibernate in Action"); - doc.setSummary("blah"); - doc.updateText("blah blah"); - fol.setName("books"); - doc.setOwner(o); - doc.setFolder(fol); - fol.getDocuments().add(doc); - s.save(o); - s.save(fol); - t.commit(); - s.close(); + SessionFactory factory = getFactory(); + Session s = factory.openSession(); + Transaction t = s.beginTransaction(); + Owner o = new Owner(); + Document doc = new Document(); + Folder fol = new Folder(); + o.setName( "gavin" ); + doc.setName( "Hibernate in Action" ); + doc.setSummary( "blah" ); + doc.updateText( "blah blah" ); + fol.setName( "books" ); + doc.setOwner( o ); + doc.setFolder( fol ); + fol.getDocuments().add( doc ); + s.save( o ); + s.save( fol ); + t.commit(); + s.close(); - s = factory.openSession(); - s.setCacheMode( CacheMode.IGNORE ); - t = s.beginTransaction(); - doc = ( Document ) s.get( Document.class, doc.getId() ); - TestCase.assertTrue( Hibernate.isPropertyInitialized(doc, "weirdProperty")); - TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "name")); - TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text")); - TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "upperCaseName")); - TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "folder")); - TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "owner")); - doc.getUpperCaseName(); // should force initialization - TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text")); - TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty")); - TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "upperCaseName")); - TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "folder")); - TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "owner")); - t.commit(); - s.close(); + s = factory.openSession(); + s.setCacheMode( CacheMode.IGNORE ); + t = s.beginTransaction(); + doc = (Document) s.get( Document.class, doc.getId() ); + TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "weirdProperty" ) ); + TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "name" ) ); + TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "text" ) ); + TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) ); + TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "folder" ) ); + TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "owner" ) ); + doc.getUpperCaseName(); // should force initialization + TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "text" ) ); + TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "weirdProperty" ) ); + TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) ); + TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "folder" ) ); + TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "owner" ) ); + t.commit(); + s.close(); - s = factory.openSession(); - s.setCacheMode( CacheMode.IGNORE ); - t = s.beginTransaction(); - doc = (Document) s.createQuery("from Document").uniqueResult(); - doc.getName(); - TestCase.assertEquals( doc.getText(), "blah blah" ); - t.commit(); - s.close(); + s = factory.openSession(); + s.setCacheMode( CacheMode.IGNORE ); + t = s.beginTransaction(); + doc = (Document) s.createQuery( "from Document" ).uniqueResult(); + doc.getName(); + TestCase.assertEquals( doc.getText(), "blah blah" ); + t.commit(); + s.close(); - s = factory.openSession(); - s.setCacheMode( CacheMode.IGNORE ); - t = s.beginTransaction(); - doc = (Document) s.createQuery("from Document").uniqueResult(); - doc.getName(); - TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text")); - TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "summary")); - TestCase.assertEquals( doc.getText(), "blah blah" ); - TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text")); - TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "summary")); - t.commit(); - s.close(); + s = factory.openSession(); + s.setCacheMode( CacheMode.IGNORE ); + t = s.beginTransaction(); + doc = (Document) s.createQuery( "from Document" ).uniqueResult(); + doc.getName(); + TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "text" ) ); + TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "summary" ) ); + TestCase.assertEquals( doc.getText(), "blah blah" ); + TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "text" ) ); + TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "summary" ) ); + t.commit(); + s.close(); - s = factory.openSession(); - s.setCacheMode( CacheMode.IGNORE ); - t = s.beginTransaction(); - doc = (Document) s.createQuery("from Document").uniqueResult(); - doc.setName("HiA"); - t.commit(); - s.close(); + s = factory.openSession(); + s.setCacheMode( CacheMode.IGNORE ); + t = s.beginTransaction(); + doc = (Document) s.createQuery( "from Document" ).uniqueResult(); + doc.setName( "HiA" ); + t.commit(); + s.close(); - s = factory.openSession(); - s.setCacheMode( CacheMode.IGNORE ); - t = s.beginTransaction(); - doc = (Document) s.createQuery("from Document").uniqueResult(); - TestCase.assertEquals( doc.getName(), "HiA" ); - TestCase.assertEquals( doc.getText(), "blah blah" ); - t.commit(); - s.close(); + s = factory.openSession(); + s.setCacheMode( CacheMode.IGNORE ); + t = s.beginTransaction(); + doc = (Document) s.createQuery( "from Document" ).uniqueResult(); + TestCase.assertEquals( doc.getName(), "HiA" ); + TestCase.assertEquals( doc.getText(), "blah blah" ); + t.commit(); + s.close(); - s = factory.openSession(); - s.setCacheMode( CacheMode.IGNORE ); - t = s.beginTransaction(); - doc = (Document) s.createQuery("from Document").uniqueResult(); - doc.getText(); - doc.setName("HiA second edition"); - t.commit(); - s.close(); + s = factory.openSession(); + s.setCacheMode( CacheMode.IGNORE ); + t = s.beginTransaction(); + doc = (Document) s.createQuery( "from Document" ).uniqueResult(); + doc.getText(); + doc.setName( "HiA second edition" ); + t.commit(); + s.close(); - s = factory.openSession(); - s.setCacheMode( CacheMode.IGNORE ); - t = s.beginTransaction(); - doc = (Document) s.createQuery("from Document").uniqueResult(); - TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty")); - TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "name")); - TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text")); - TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "upperCaseName")); - TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "owner")); - TestCase.assertEquals( doc.getName(), "HiA second edition" ); - TestCase.assertEquals( doc.getText(), "blah blah" ); - TestCase.assertEquals( doc.getUpperCaseName(), "HIA SECOND EDITION" ); - TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text")); - TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty")); - TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "upperCaseName")); - t.commit(); - s.close(); + s = factory.openSession(); + s.setCacheMode( CacheMode.IGNORE ); + t = s.beginTransaction(); + doc = (Document) s.createQuery( "from Document" ).uniqueResult(); + TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "weirdProperty" ) ); + TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "name" ) ); + TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "text" ) ); + TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) ); + TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "owner" ) ); + TestCase.assertEquals( doc.getName(), "HiA second edition" ); + TestCase.assertEquals( doc.getText(), "blah blah" ); + TestCase.assertEquals( doc.getUpperCaseName(), "HIA SECOND EDITION" ); + TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "text" ) ); + TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "weirdProperty" ) ); + TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) ); + t.commit(); + s.close(); - s = factory.openSession(); - s.setCacheMode( CacheMode.IGNORE ); - t = s.beginTransaction(); - doc = (Document) s.createQuery("from Document").uniqueResult(); - t.commit(); - s.close(); + s = factory.openSession(); + s.setCacheMode( CacheMode.IGNORE ); + t = s.beginTransaction(); + doc = (Document) s.createQuery( "from Document" ).uniqueResult(); + t.commit(); + s.close(); - TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text")); + TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "text" ) ); - s = factory.openSession(); - s.setCacheMode( CacheMode.IGNORE ); - t = s.beginTransaction(); - s.lock(doc, LockMode.NONE); - TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text")); - TestCase.assertEquals( doc.getText(), "blah blah" ); - TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text")); - t.commit(); - s.close(); + s = factory.openSession(); + s.setCacheMode( CacheMode.IGNORE ); + t = s.beginTransaction(); + s.lock( doc, LockMode.NONE ); + TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "text" ) ); + TestCase.assertEquals( doc.getText(), "blah blah" ); + TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "text" ) ); + t.commit(); + s.close(); - s = factory.openSession(); - s.setCacheMode( CacheMode.IGNORE ); - t = s.beginTransaction(); - doc = (Document) s.createQuery("from Document").uniqueResult(); - t.commit(); - s.close(); + s = factory.openSession(); + s.setCacheMode( CacheMode.IGNORE ); + t = s.beginTransaction(); + doc = (Document) s.createQuery( "from Document" ).uniqueResult(); + t.commit(); + s.close(); - doc.setName("HiA2"); + doc.setName( "HiA2" ); - TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text")); + TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "text" ) ); - s = factory.openSession(); - s.setCacheMode( CacheMode.IGNORE ); - t = s.beginTransaction(); - s.saveOrUpdate(doc); - s.flush(); - TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text")); - TestCase.assertEquals( doc.getText(), "blah blah" ); - TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text")); - doc.updateText("blah blah blah blah"); - t.commit(); - s.close(); + s = factory.openSession(); + s.setCacheMode( CacheMode.IGNORE ); + t = s.beginTransaction(); + s.saveOrUpdate( doc ); + s.flush(); + TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "text" ) ); + TestCase.assertEquals( doc.getText(), "blah blah" ); + TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "text" ) ); + doc.updateText( "blah blah blah blah" ); + t.commit(); + s.close(); - s = factory.openSession(); - s.setCacheMode( CacheMode.IGNORE ); - t = s.beginTransaction(); - doc = ( Document ) s.createQuery("from Document").uniqueResult(); - TestCase.assertEquals( doc.getName(), "HiA2" ); - TestCase.assertEquals( doc.getText(), "blah blah blah blah" ); - t.commit(); - s.close(); + s = factory.openSession(); + s.setCacheMode( CacheMode.IGNORE ); + t = s.beginTransaction(); + doc = (Document) s.createQuery( "from Document" ).uniqueResult(); + TestCase.assertEquals( doc.getName(), "HiA2" ); + TestCase.assertEquals( doc.getText(), "blah blah blah blah" ); + t.commit(); + s.close(); - s = factory.openSession(); - s.setCacheMode( CacheMode.IGNORE ); - t = s.beginTransaction(); - doc = (Document) s.load( Document.class, doc.getId() ); - doc.getName(); - TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text")); - TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "summary")); - t.commit(); - s.close(); + s = factory.openSession(); + s.setCacheMode( CacheMode.IGNORE ); + t = s.beginTransaction(); + doc = (Document) s.load( Document.class, doc.getId() ); + doc.getName(); + TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "text" ) ); + TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "summary" ) ); + t.commit(); + s.close(); - s = factory.openSession(); - s.setCacheMode( CacheMode.IGNORE ); - t = s.beginTransaction(); - doc = (Document) s.createQuery("from Document").uniqueResult(); - //s.delete(doc); - s.delete( doc.getFolder() ); - s.delete( doc.getOwner() ); - s.flush(); - t.commit(); - s.close(); + s = factory.openSession(); + s.setCacheMode( CacheMode.IGNORE ); + t = s.beginTransaction(); + doc = (Document) s.createQuery( "from Document" ).uniqueResult(); + //s.delete(doc); + s.delete( doc.getFolder() ); + s.delete( doc.getOwner() ); + s.flush(); + t.commit(); + s.close(); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/instrument/cases/TestLazyPropertyCustomTypeExecutable.java b/hibernate-core/src/test/java/org/hibernate/test/instrument/cases/TestLazyPropertyCustomTypeExecutable.java index b17afd2472..ae9a4753c6 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/instrument/cases/TestLazyPropertyCustomTypeExecutable.java +++ b/hibernate-core/src/test/java/org/hibernate/test/instrument/cases/TestLazyPropertyCustomTypeExecutable.java @@ -13,11 +13,11 @@ import org.hibernate.test.instrument.domain.Problematic; * @author Steve Ebersole */ public class TestLazyPropertyCustomTypeExecutable extends AbstractExecutable { - + @Override protected String[] getResources() { return new String[] { "org/hibernate/test/instrument/domain/Problematic.hbm.xml" }; } - + @Override public void execute() throws Exception { Session s = getFactory().openSession(); Problematic p = new Problematic(); @@ -76,7 +76,7 @@ public class TestLazyPropertyCustomTypeExecutable extends AbstractExecutable { s.close(); } } - + @Override protected void cleanup() { Session s = getFactory().openSession(); s.beginTransaction(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/instrument/runtime/AbstractTransformingClassLoaderInstrumentTestCase.java b/hibernate-core/src/test/java/org/hibernate/test/instrument/runtime/AbstractTransformingClassLoaderInstrumentTestCase.java index 421400149d..a5bddde88d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/instrument/runtime/AbstractTransformingClassLoaderInstrumentTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/test/instrument/runtime/AbstractTransformingClassLoaderInstrumentTestCase.java @@ -34,6 +34,7 @@ import org.hibernate.bytecode.buildtime.spi.FieldFilter; import org.hibernate.bytecode.spi.BytecodeProvider; import org.hibernate.bytecode.spi.InstrumentedClassLoader; import org.hibernate.dialect.MySQLDialect; +import org.hibernate.internal.util.ReflectHelper; import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.testing.junit4.ClassLoadingIsolater; @@ -136,8 +137,10 @@ public abstract class AbstractTransformingClassLoaderInstrumentTestCase extends // reflection code to ensure isolation into the created classloader ~~~~~~~ - private static final Class[] SIG = new Class[] {}; - private static final Object[] ARGS = new Object[] {}; + private static final Class[] SIG_METAMODEL = new Class[]{ClassLoader.class}; + private static final String PREPARE = "prepare"; + private static final String EXECUTE = "execute"; + private static final String COMPLETE = "complete"; public void executeExecutable(String name) { Class execClass = null; @@ -150,8 +153,14 @@ public abstract class AbstractTransformingClassLoaderInstrumentTestCase extends throw new HibernateException( "could not load executable", t ); } try { - execClass.getMethod( "prepare", SIG ).invoke( executable, ARGS ); - execClass.getMethod( "execute", SIG ).invoke( executable, ARGS ); + if ( BaseUnitTestCase.isMetadataUsed() ) { + execClass.getMethod( PREPARE, SIG_METAMODEL ) + .invoke( executable, new ClassLoader[] { Thread.currentThread().getContextClassLoader() } ); + } + else { + execClass.getMethod( PREPARE, ReflectHelper.NO_PARAM_SIGNATURE ).invoke( executable, ReflectHelper.NO_PARAMS ); + } + execClass.getMethod( EXECUTE, ReflectHelper.NO_PARAM_SIGNATURE ).invoke( executable, ReflectHelper.NO_PARAMS ); } catch ( NoSuchMethodException e ) { throw new HibernateException( "could not exeucte executable", e ); @@ -164,7 +173,7 @@ public abstract class AbstractTransformingClassLoaderInstrumentTestCase extends } finally { try { - execClass.getMethod( "complete", SIG ).invoke( executable, ARGS ); + execClass.getMethod( COMPLETE, ReflectHelper.NO_PARAM_SIGNATURE ).invoke( executable, ReflectHelper.NO_PARAMS ); } catch ( Throwable ignore ) { } diff --git a/hibernate-core/src/test/java/org/hibernate/test/instrument/runtime/JavassistInstrumentationTest.java b/hibernate-core/src/test/java/org/hibernate/test/instrument/runtime/JavassistInstrumentationTest.java index 47b9e5ca21..b5cf42f8de 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/instrument/runtime/JavassistInstrumentationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/instrument/runtime/JavassistInstrumentationTest.java @@ -23,14 +23,47 @@ */ package org.hibernate.test.instrument.runtime; +import org.junit.Test; + import org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl; import org.hibernate.bytecode.spi.BytecodeProvider; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; /** * @author Steve Ebersole */ public class JavassistInstrumentationTest extends AbstractTransformingClassLoaderInstrumentTestCase { + @Override protected BytecodeProvider buildBytecodeProvider() { return new BytecodeProviderImpl(); } + + @FailureExpectedWithNewMetamodel + @Test + @Override + public void testLazy() { + super.testLazy(); + } + + @FailureExpectedWithNewMetamodel + @Test + @Override + public void testLazyManyToOne() { + super.testLazyManyToOne(); + } + + @FailureExpectedWithNewMetamodel + @Test + @Override + public void testSharedPKOneToOne() { + super.testSharedPKOneToOne(); + } + + @FailureExpectedWithNewMetamodel + @Test + @Override + public void testManyToOneProxy() { + super.testManyToOneProxy(); + } + } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metadata/SecondMetadataTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metadata/SecondMetadataTest.java index 3c2e5f1cb0..791e34fc3a 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metadata/SecondMetadataTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metadata/SecondMetadataTest.java @@ -28,14 +28,12 @@ import javax.persistence.EntityManagerFactory; import org.junit.Test; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import static org.junit.Assert.assertNotNull; /** * @author Emmanuel Bernard */ -@FailureExpectedWithNewMetamodel public class SecondMetadataTest extends BaseEntityManagerFunctionalTestCase { @Test public void testBaseOfService() throws Exception { diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java index 9aa9583b16..49ecb7cab2 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java @@ -508,7 +508,6 @@ public class InfinispanRegionFactory extends AbstractRegionFactory { TypeOverrides regionOverride = typeOverrides.get(regionName); if (!definedConfigurations.contains(regionName)) { String templateCacheName; - Configuration regionCacheCfg; ConfigurationBuilder builder = new ConfigurationBuilder(); if (regionOverride != null) { if (log.isDebugEnabled()) log.debug("Cache region specific configuration exists: " + regionOverride); @@ -556,8 +555,7 @@ public class InfinispanRegionFactory extends AbstractRegionFactory { .getGlobalComponentRegistry(); Map factories = - (Map) globalCr - .getComponent("org.infinispan.modules.command.factories"); + globalCr.getComponent("org.infinispan.modules.command.factories"); for (ModuleCommandFactory factory : factories.values()) { if (factory instanceof CacheCommandFactory) diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/ClusterAwareRegionFactory.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/ClusterAwareRegionFactory.java index 877de15ba0..275387b109 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/ClusterAwareRegionFactory.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/ClusterAwareRegionFactory.java @@ -71,15 +71,17 @@ public class ClusterAwareRegionFactory extends AbstractRegionFactory { } public static void clearCacheManagers() { - for ( EmbeddedCacheManager manager : cacheManagers.values() ) { - try { + try { + for ( EmbeddedCacheManager manager : cacheManagers.values() ) { manager.stop(); } - catch ( Exception e ) { - log.error( "Exception cleaning up CacheManager " + manager, e ); - } } - cacheManagers.clear(); + catch ( Exception e ) { + log.error( "Exception cleaning up CacheManager ", e ); + } + finally { + cacheManagers.clear(); + } } @Override @@ -109,11 +111,11 @@ public class ClusterAwareRegionFactory extends AbstractRegionFactory { delegate.setCacheManager( existing ); } } - + @Override public void start(Settings settings, Properties properties) throws CacheException { start(); } - + @Override public void stop() { if ( locallyAdded ) { cacheManagers.remove( cacheManagerName ); @@ -121,11 +123,12 @@ public class ClusterAwareRegionFactory extends AbstractRegionFactory { delegate.stop(); } + @Override public CollectionRegion buildCollectionRegion(String regionName, Properties properties, CacheDataDescription metadata) throws CacheException { return delegate.buildCollectionRegion( regionName, properties, metadata ); } - + @Override public EntityRegion buildEntityRegion(String regionName, Properties properties, CacheDataDescription metadata) throws CacheException { return delegate.buildEntityRegion( regionName, properties, metadata ); @@ -136,17 +139,17 @@ public class ClusterAwareRegionFactory extends AbstractRegionFactory { throws CacheException { return delegate.buildNaturalIdRegion( regionName, properties, metadata ); } - + @Override public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties properties) throws CacheException { return delegate.buildQueryResultsRegion( regionName, properties ); } - + @Override public TimestampsRegion buildTimestampsRegion(String regionName, Properties properties) throws CacheException { return delegate.buildTimestampsRegion( regionName, properties ); } - + @Override public boolean isMinimalPutsEnabledByDefault() { return delegate.isMinimalPutsEnabledByDefault(); } @@ -155,7 +158,7 @@ public class ClusterAwareRegionFactory extends AbstractRegionFactory { public AccessType getDefaultAccessType() { return AccessType.TRANSACTIONAL; } - + @Override public long nextTimestamp() { return delegate.nextTimestamp(); } diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/DualNodeTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/DualNodeTestCase.java index 6cc6f55be5..664c2fb643 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/DualNodeTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/DualNodeTestCase.java @@ -90,6 +90,7 @@ public abstract class DualNodeTestCase extends BaseCoreFunctionalTestCase { protected void cleanupTransactionManagement() { DualNodeJtaTransactionManagerImpl.cleanupTransactions(); DualNodeJtaTransactionManagerImpl.cleanupTransactionManagers(); + ClusterAwareRegionFactory.clearCacheManagers(); } @Before diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/ClassLoadingIsolater.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/ClassLoadingIsolater.java index 8b5118dfe6..48cfc355ee 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/ClassLoadingIsolater.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/ClassLoadingIsolater.java @@ -42,6 +42,10 @@ public class ClassLoadingIsolater implements MethodRule { this.provider = provider; } + public IsolatedClassLoaderProvider getProvider() { + return provider; + } + @Override public Statement apply(final Statement base, FrameworkMethod method, Object target) { return new Statement() { diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java index 75ccf200c0..a16f075a61 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java @@ -84,7 +84,6 @@ public class CustomRunner extends BlockJUnit4ClassRunner { private Boolean isAllTestsIgnored = null; private Object testInstance; private List computedTestMethods; - private Boolean useNewMetamodel; private boolean beforeClassMethodFailed; public CustomRunner(Class clazz) throws InitializationError { @@ -268,10 +267,7 @@ public class CustomRunner extends BlockJUnit4ClassRunner { } boolean useNewMetamodel() { - if ( useNewMetamodel == null ) { - useNewMetamodel = Boolean.valueOf( System.getProperty( BaseCoreFunctionalTestCase.USE_NEW_METADATA_MAPPINGS, "true" ) ); - } - return useNewMetamodel; + return BaseUnitTestCase.isMetadataUsed(); } protected Ignore convertSkipToIgnore(FrameworkMethod frameworkMethod) {