diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/CollectionHelper.java b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/CollectionHelper.java index 3b43c59c5f..eff1786109 100755 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/CollectionHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/CollectionHelper.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -181,4 +182,17 @@ public final class CollectionHelper { copy.putAll( map ); return copy; } + + public static void cleanUpNullValue(Map map) { + if ( isEmpty( map ) ) { + return; + } + Iterator itr = map.entrySet().iterator(); + while ( itr.hasNext() ) { + final Map.Entry entry = (Map.Entry) itr.next(); + if ( entry.getValue() == null ) { + itr.remove(); + } + } + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataSources.java b/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataSources.java index 7404d42bbb..87942d4cfc 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataSources.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataSources.java @@ -40,7 +40,6 @@ import java.util.zip.ZipEntry; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.ClassInfo; -import org.jboss.jandex.Index; import org.jboss.jandex.IndexView; import org.jboss.jandex.Indexer; import org.jboss.logging.Logger; @@ -75,7 +74,10 @@ import org.hibernate.service.ServiceRegistry; */ public class MetadataSources { private static final Logger LOG = Logger.getLogger( MetadataSources.class ); - + /** + * temporary option + */ + public static final String USE_NEW_METADATA_MAPPINGS = "hibernate.test.new_metadata_mappings"; private final ServiceRegistry serviceRegistry; private final JaxbMappingProcessor jaxbProcessor; private final List externalCacheRegionDefinitions = new ArrayList(); @@ -444,12 +446,14 @@ public class MetadataSources { */ public MetadataSources addDirectory(File dir) { File[] files = dir.listFiles(); - for ( File file : files ) { - if ( file.isDirectory() ) { - addDirectory( file ); - } - else if ( file.getName().endsWith( ".hbm.xml" ) ) { - addFile( file ); + if ( files != null && files.length > 0 ) { + for ( File file : files ) { + if ( file.isDirectory() ) { + addDirectory( file ); + } + else if ( file.getName().endsWith( ".hbm.xml" ) ) { + addFile( file ); + } } } return this; @@ -526,7 +530,7 @@ public class MetadataSources { for ( Class fieldType : ReflectHelper.getFieldTypes( clazz ) ) { if ( !fieldType.isPrimitive() && fieldType != Object.class ) { try { - Index fieldIndex = JandexHelper.indexForClass( + IndexView fieldIndex = JandexHelper.indexForClass( serviceRegistry.getService( ClassLoaderService.class ), fieldType ); if ( !fieldIndex.getAnnotations( diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java index 0be2aeabd0..d9651cdc4e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java @@ -299,6 +299,7 @@ public class Binder { entityHierarchyHelper.applyToAllEntityHierarchies( entityHierarchiesByRootEntityName.values(), rootExecutor, subExecutor ); } + private void bindEntityHierarchiesExcludingNonIdAttributeBindings() { LocalBindingContextExecutor rootEntityCallback = new LocalBindingContextExecutor() { @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataImpl.java index 4c6048d117..073509a9f8 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataImpl.java @@ -24,6 +24,8 @@ package org.hibernate.metamodel.internal; import java.io.Serializable; +import java.sql.Blob; +import java.sql.Clob; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -39,6 +41,7 @@ import org.hibernate.MappingException; import org.hibernate.SessionFactory; import org.hibernate.annotations.common.util.StringHelper; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.boot.spi.CacheRegionDefinition; import org.hibernate.cache.spi.access.AccessType; import org.hibernate.cfg.NamingStrategy; import org.hibernate.cfg.ObjectNameNormalizer; @@ -66,8 +69,10 @@ import org.hibernate.metamodel.spi.MetadataImplementor; import org.hibernate.metamodel.spi.MetadataSourceProcessor; import org.hibernate.metamodel.spi.TypeContributions; import org.hibernate.metamodel.spi.TypeContributor; +import org.hibernate.metamodel.spi.binding.AbstractPluralAttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.BackRefAttributeBinding; +import org.hibernate.metamodel.spi.binding.Caching; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.FetchProfile; import org.hibernate.metamodel.spi.binding.IdGenerator; @@ -249,7 +254,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable { binder.addEntityHierarchies( processor.extractEntityHierarchies() ); binder.bindEntityHierarchies(); - secondPass(); + secondPass(metadataSources); } @@ -271,7 +276,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable { } } - private void secondPass() { + private void secondPass(MetadataSources metadataSources) { // This must be done outside of Table, rather than statically, to ensure // deterministic alias names. See HHH-2448. int uniqueInteger = 0; @@ -280,6 +285,44 @@ public class MetadataImpl implements MetadataImplementor, Serializable { table.setTableNumber( uniqueInteger++ ); } } + + if ( metadataSources.getExternalCacheRegionDefinitions().isEmpty() ) { + return; + } + for ( CacheRegionDefinition cacheRegionDefinition : metadataSources.getExternalCacheRegionDefinitions() ) { + final String role = cacheRegionDefinition.getRole(); + if ( cacheRegionDefinition.getRegionType() == CacheRegionDefinition.CacheRegionType.ENTITY ) { + EntityBinding entityBinding = entityBindingMap.get( role ); + if ( entityBinding != null ) { + entityBinding.getHierarchyDetails() + .setCaching( + new Caching( + cacheRegionDefinition.getRegion(), + AccessType.fromExternalName( cacheRegionDefinition.getUsage() ), + cacheRegionDefinition.isCacheLazy() + ) + ); + }else{ + //logging? + throw new MappingException( "Can't find entitybinding for role " + role +" to apply cache configuration" ); + } + + } + else if ( cacheRegionDefinition.getRegionType() == CacheRegionDefinition.CacheRegionType.COLLECTION ) { + PluralAttributeBinding pluralAttributeBinding = collectionBindingMap.get( role ); + if(pluralAttributeBinding!=null){ + AbstractPluralAttributeBinding.class.cast( pluralAttributeBinding ).setCaching( new Caching( + cacheRegionDefinition.getRegion(), + AccessType.fromExternalName( cacheRegionDefinition.getUsage() ), + cacheRegionDefinition.isCacheLazy() + ) ); + } else { + //logging? + throw new MappingException( "Can't find entitybinding for role " + role +" to apply cache configuration" ); + } + } + } + } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/AssociationAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/AssociationAttribute.java index a969b49bef..6c0803d524 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/AssociationAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/AssociationAttribute.java @@ -38,6 +38,7 @@ import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; import org.jboss.jandex.Index; +import org.jboss.jandex.IndexView; import org.jboss.logging.Logger; import org.hibernate.annotations.FetchMode; @@ -494,7 +495,7 @@ public class AssociationAttribute extends MappedAttribute { // with the owning side. if ( isJpaInverse ) { // TODO: Pull some of this into JandexHelper. - Index index = JandexHelper.indexForClass( + IndexView index = JandexHelper.indexForClass( getContext().getServiceRegistry().getService( ClassLoaderService.class ), referencedAttributeType ); ClassInfo classInfo = index.getClassByName( DotName.createSimple( diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/QueryProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/QueryProcessor.java index 41c63ff364..0de2727c72 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/QueryProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/QueryProcessor.java @@ -25,6 +25,7 @@ package org.hibernate.metamodel.internal.source.annotations.global; import java.util.Collection; import java.util.HashMap; +import javax.persistence.LockModeType; import javax.persistence.NamedNativeQueries; import javax.persistence.NamedNativeQuery; import javax.persistence.NamedQueries; @@ -35,10 +36,14 @@ import org.jboss.jandex.AnnotationValue; import org.jboss.logging.Logger; import org.hibernate.AnnotationException; +import org.hibernate.AssertionFailure; import org.hibernate.CacheMode; import org.hibernate.FlushMode; import org.hibernate.LockMode; +import org.hibernate.LockOptions; import org.hibernate.MappingException; +import org.hibernate.annotations.CacheModeType; +import org.hibernate.annotations.FlushModeType; import org.hibernate.annotations.QueryHints; import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn; @@ -46,6 +51,7 @@ import org.hibernate.engine.spi.NamedQueryDefinitionBuilder; import org.hibernate.engine.spi.NamedSQLQueryDefinition; import org.hibernate.engine.spi.NamedSQLQueryDefinitionBuilder; import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.internal.util.LockModeConverter; import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext; import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames; @@ -135,13 +141,98 @@ public class QueryProcessor { * @param annotation the named query annotation */ private static void bindNamedQuery(MetadataImplementor metadata, AnnotationInstance annotation) { - String name = JandexHelper.getValue( annotation, "name", String.class ); + final String name = JandexHelper.getValue( annotation, "name", String.class ); if ( StringHelper.isEmpty( name ) ) { throw new AnnotationException( "A named query must have a name when used in class or package level" ); } + NamedQueryDefinitionBuilder builder = new NamedQueryDefinitionBuilder(); + builder.setName( name ); - String query = JandexHelper.getValue( annotation, "query", String.class ); + final String query = JandexHelper.getValue( annotation, "query", String.class ); + builder.setQuery( query ); + if ( annotation.name().equals( JPADotNames.NAMED_QUERY ) ) { + bindJPANamedQuery( annotation, builder, name, query ); + } else { + builder.setFlushMode( + getFlushMode( + JandexHelper.getEnumValue( + annotation, + "flushMode", + FlushModeType.class + ) + ) + ) + .setCacheable( JandexHelper.getValue( annotation, "cacheable", Boolean.class ) ) + .setCacheRegion( JandexHelper.getValue( annotation, "cacheRegion", String.class ) ) + .setFetchSize( JandexHelper.getValue( annotation, "fetchSize", Integer.class ) ) + .setTimeout( JandexHelper.getValue( annotation, "timeout", Integer.class ) ) + .setComment( JandexHelper.getValue( annotation, "comment", String.class ) ) + .setCacheMode( + getCacheMode( + JandexHelper.getValue( + annotation, + "cacheMode", + CacheModeType.class + ) + ) + ) + .setReadOnly( JandexHelper.getValue( annotation, "readOnly", Boolean.class ) ); + } + + metadata.addNamedQuery(builder.createNamedQueryDefinition()); + LOG.debugf( "Binding named query: %s => %s", name, query ); + } + + public static FlushMode getFlushMode(FlushModeType flushModeType) { + FlushMode flushMode; + switch ( flushModeType ) { + case ALWAYS: + flushMode = FlushMode.ALWAYS; + break; + case AUTO: + flushMode = FlushMode.AUTO; + break; + case COMMIT: + flushMode = FlushMode.COMMIT; + break; + case NEVER: + flushMode = FlushMode.MANUAL; + break; + case MANUAL: + flushMode = FlushMode.MANUAL; + break; + case PERSISTENCE_CONTEXT: + flushMode = null; + break; + default: + throw new AssertionFailure( "Unknown flushModeType: " + flushModeType ); + } + return flushMode; + } + private static CacheMode getCacheMode(CacheModeType cacheModeType) { + switch ( cacheModeType ) { + case GET: + return CacheMode.GET; + case IGNORE: + return CacheMode.IGNORE; + case NORMAL: + return CacheMode.NORMAL; + case PUT: + return CacheMode.PUT; + case REFRESH: + return CacheMode.REFRESH; + default: + throw new AssertionFailure( "Unknown cacheModeType: " + cacheModeType ); + } + } + + + private static void bindJPANamedQuery( + AnnotationInstance annotation, + NamedQueryDefinitionBuilder builder, + String name, + String query){ AnnotationInstance[] hints = JandexHelper.getValue( annotation, "hints", AnnotationInstance[].class ); String cacheRegion = getString( hints, QueryHints.CACHE_REGION ); @@ -159,6 +250,12 @@ public class QueryProcessor { if ( lockTimeout != null && lockTimeout < 0 ) { lockTimeout = null; } + LockOptions lockOptions = new LockOptions( LockModeConverter.convertToLockMode( JandexHelper.getEnumValue( annotation, "lockMode", + LockModeType.class + ) ) ); + if ( lockTimeout != null ) { + lockOptions.setTimeOut( lockTimeout ); + } Integer fetchSize = getInteger( hints, QueryHints.FETCH_SIZE, name ); if ( fetchSize != null && fetchSize < 0 ) { fetchSize = null; @@ -168,23 +265,16 @@ public class QueryProcessor { if ( StringHelper.isEmpty( comment ) ) { comment = null; } - - metadata.addNamedQuery( - new NamedQueryDefinitionBuilder() - .setName( name ) - .setQuery( query ) - .setCacheable( getBoolean( hints, QueryHints.CACHEABLE, name ) ) - .setCacheRegion( cacheRegion ) - .setTimeout( timeout ) - .setFetchSize( fetchSize ) - .setFlushMode( getFlushMode( hints, QueryHints.FLUSH_MODE, name ) ) - .setCacheMode( getCacheMode( hints, QueryHints.CACHE_MODE, name ) ) - .setReadOnly( getBoolean( hints, QueryHints.READ_ONLY, name ) ) - .setComment( comment ) - .setParameterTypes( null ) - .createNamedQueryDefinition() - ); - LOG.debugf( "Binding named query: %s => %s", name, query ); + builder.setCacheable( getBoolean( hints, QueryHints.CACHEABLE, name ) ) + .setCacheRegion( cacheRegion ) + .setTimeout( timeout ) + .setLockOptions( lockOptions ) + .setFetchSize( fetchSize ) + .setFlushMode( getFlushMode( hints, QueryHints.FLUSH_MODE, name ) ) + .setCacheMode( getCacheMode( hints, QueryHints.CACHE_MODE, name ) ) + .setReadOnly( getBoolean( hints, QueryHints.READ_ONLY, name ) ) + .setComment( comment ) + .setParameterTypes( null ); } private static void bindNamedNativeQuery(MetadataImplementor metadata, AnnotationInstance annotation) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/SqlResultSetProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/SqlResultSetProcessor.java index ba9c1f5dc3..edef8eaad5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/SqlResultSetProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/SqlResultSetProcessor.java @@ -120,14 +120,14 @@ public class SqlResultSetProcessor { private static void bindEntityResult(final AnnotationBindingContext bindingContext, final AnnotationInstance entityResult, final ResultSetMappingDefinition definition) { - final Class entityClass = JandexHelper.getValue( entityResult, "entityClass", Class.class ); - final String className = entityClass.getName(); +// final Class entityClass = JandexHelper.getValue( entityResult, "entityClass", Class.class ); + final String className = JandexHelper.getValue( entityResult, "entityClass", String.class ); //todo look up the whole entitybindings to find the right one seems stupid, but there is no way to look entitybinding //by class name, since with hbm, hibernate actually supports map one class to multi entities. final Iterable entityBindings = bindingContext.getMetadataImplementor().getEntityBindings(); EntityBinding targetEntityBinding = null; for ( final EntityBinding entityBinding : entityBindings ) { - if ( className.equals( entityBinding.getEntity().getClass() ) ) { + if ( className.equals( entityBinding.getEntity().getClassName() ) ) { targetEntityBinding = entityBinding; break; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/EntityHierarchyBuilder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/EntityHierarchyBuilder.java index 5f43ee80fa..ff909c6621 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/EntityHierarchyBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/EntityHierarchyBuilder.java @@ -41,6 +41,7 @@ import org.jboss.jandex.MethodInfo; import org.jboss.logging.Logger; import org.hibernate.AnnotationException; +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext; import org.hibernate.metamodel.internal.source.annotations.EntityHierarchyImpl; @@ -52,6 +53,7 @@ import org.hibernate.metamodel.internal.source.annotations.entity.RootEntityClas import org.hibernate.metamodel.spi.binding.InheritanceType; import org.hibernate.metamodel.spi.source.EntityHierarchy; import org.hibernate.metamodel.spi.source.EntitySource; +import org.hibernate.metamodel.spi.source.MappingException; import org.hibernate.metamodel.spi.source.SubclassEntitySource; /** @@ -87,8 +89,7 @@ public class EntityHierarchyBuilder { if ( processedEntities.contains( classInfo.name() ) ) { continue; } - - ClassInfo rootClassInfo = findRootEntityClassInfo( index, classInfo ); + ClassInfo rootClassInfo = findRootEntityClassInfo( index, classInfo, bindingContext ); List rootClassWithAllSubclasses = new ArrayList(); // collect the current root entity and all its subclasses @@ -181,7 +182,7 @@ public class EntityHierarchyBuilder { * * @return Finds the root entity starting at the entity given by {@code info} */ - private static ClassInfo findRootEntityClassInfo(IndexView index, ClassInfo info) { + private static ClassInfo findRootEntityClassInfo(IndexView index, ClassInfo info, AnnotationBindingContext bindingContext) { ClassInfo rootEntity = info; DotName superName = info.superName(); @@ -189,6 +190,20 @@ public class EntityHierarchyBuilder { // walk up the hierarchy until java.lang.Object while ( !OBJECT.equals( superName ) ) { tmpInfo = index.getClassByName( superName ); + if ( tmpInfo == null && superName != null ) { + Class clazz = bindingContext.locateClassByName( superName.toString() ); + if ( clazz != null ) { + throw new AnnotationException( + info.name() + .toString() + "'s parent class [" + clazz.getName() + "] is not added into Jandex repository" + ); + }else { + throw new AnnotationException( + info.name() + .toString() + "'s parent class [" + superName.toString() + "] doesn't exist in classpath" + ); + } + } if ( isEntityClass( tmpInfo ) ) { rootEntity = tmpInfo; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JandexHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JandexHelper.java index 1e4960ecd7..2a9a4b4eca 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JandexHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JandexHelper.java @@ -43,6 +43,7 @@ import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; import org.jboss.jandex.FieldInfo; import org.jboss.jandex.Index; +import org.jboss.jandex.IndexView; import org.jboss.jandex.Indexer; import org.jboss.jandex.MethodInfo; import org.jboss.jandex.Type; @@ -304,7 +305,7 @@ public class JandexHelper { * * @return an annotation repository w/ all the annotation discovered in the specified classes */ - public static Index indexForClass(ClassLoaderService classLoaderService, Class... classes) { + public static IndexView indexForClass(ClassLoaderService classLoaderService, Class... classes) { Indexer indexer = new Indexer(); for ( Class clazz : classes ) { InputStream stream = classLoaderService.locateResourceStream( diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/IndexBuilder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/IndexBuilder.java index a67fb7f7a9..5085754673 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/IndexBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/IndexBuilder.java @@ -39,6 +39,7 @@ import org.jboss.logging.Logger; import org.hibernate.AssertionFailure; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; @@ -221,16 +222,27 @@ public class IndexBuilder { return serviceRegistry; } - ClassInfo createClassInfo(String className) { + ClassInfo createClassInfo(String className, String optionalPerfix){ if ( StringHelper.isEmpty( className ) ) { throw new AssertionFailure( "Class Name used to create ClassInfo is empty." ); } + Class clazz = null; + try { + clazz = serviceRegistry.getService( ClassLoaderService.class ).classForName( className ); + } + catch ( ClassLoadingException e ) { + if ( StringHelper.isNotEmpty( optionalPerfix ) ) { + className = StringHelper.qualify( optionalPerfix, className ); + clazz = serviceRegistry.getService( ClassLoaderService.class ) + .classForName( className ); + } + } DotName classDotName = DotName.createSimple( className ); if ( classes.containsKey( classDotName ) ) { //classInfoAnnotationsMap.put( classDotName, new HashMap>(classes.get( classDotName ).annotations()) ); return classes.get( classDotName ); } - Class clazz = serviceRegistry.getService( ClassLoaderService.class ).classForName( className ); + DotName superName = null; DotName[] interfaces = null; short access_flag; @@ -265,6 +277,10 @@ public class IndexBuilder { return classInfo; } + ClassInfo createClassInfo(String className) { + return createClassInfo( className, null ); + } + private void addSubClasses(DotName superClassDotName, ClassInfo classInfo) { if ( superClassDotName != null ) { List classInfoList = subclasses.get( superClassDotName ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/ListenerMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/ListenerMocker.java index 2e0eb6e2a4..638ca5397d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/ListenerMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/ListenerMocker.java @@ -33,6 +33,7 @@ import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; import org.hibernate.MappingException; +import org.hibernate.internal.util.StringHelper; import org.hibernate.jaxb.spi.orm.JaxbEntityListener; import org.hibernate.jaxb.spi.orm.JaxbEntityListeners; @@ -57,15 +58,20 @@ class ListenerMocker extends AbstractMocker { List clazzNameList = new ArrayList( entityListeners.getEntityListener().size() ); for ( JaxbEntityListener listener : entityListeners.getEntityListener() ) { MockHelper.addToCollectionIfNotNull( clazzNameList, listener.getClazz() ); - parserEntityListener( listener ); + parserEntityListener( listener, clazzNameList ); } MockHelper.classArrayValue( "value", clazzNameList, annotationValueList, indexBuilder.getServiceRegistry() ); return create( ENTITY_LISTENERS, classInfo, annotationValueList ); } - private void parserEntityListener(JaxbEntityListener listener) { + private void parserEntityListener(JaxbEntityListener listener, List clazzNameList) { String clazz = listener.getClazz(); - ClassInfo tempClassInfo = indexBuilder.createClassInfo( clazz ); + String defaultPackageName = classInfo!=null ? StringHelper.qualifier(classInfo.name().toString()) : null; + ClassInfo tempClassInfo = indexBuilder.createClassInfo( clazz,defaultPackageName ); + if ( !clazz.equals( tempClassInfo.name().toString() ) ) { + clazzNameList.remove( clazz ); + clazzNameList.add( tempClassInfo.name().toString() ); + } ListenerMocker mocker = createListenerMocker( indexBuilder, tempClassInfo ); mocker.parser( listener.getPostLoad(), POST_LOAD ); mocker.parser( listener.getPostPersist(), POST_PERSIST ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/MockHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/MockHelper.java index 53e92306e7..4547ae5fec 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/MockHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/MockHelper.java @@ -392,9 +392,9 @@ public class MockHelper { Method.setAccessible( methods, true ); for ( Method method : methods ) { // if the method has parameters, skip it - if ( method.getParameterTypes().length != 0 ) { - continue; - } +// if ( method.getParameterTypes().length != 0 ) { +// continue; +// } // if the method is a "bridge", skip it if ( method.isBridge() ) { continue; diff --git a/hibernate-core/src/main/java/org/hibernate/persister/internal/PersisterFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/persister/internal/PersisterFactoryImpl.java index c8e653a322..fd8f5aab7b 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/internal/PersisterFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/internal/PersisterFactoryImpl.java @@ -134,11 +134,12 @@ public final class PersisterFactoryImpl implements PersisterFactory, ServiceRegi @Override @SuppressWarnings( {"unchecked"}) - public EntityPersister createEntityPersister(EntityBinding metadata, - EntityRegionAccessStrategy cacheAccessStrategy, - NaturalIdRegionAccessStrategy naturalIdRegionAccessStrategy, - SessionFactoryImplementor factory, - Mapping cfg) { + public EntityPersister createEntityPersister( + EntityBinding metadata, + EntityRegionAccessStrategy cacheAccessStrategy, + NaturalIdRegionAccessStrategy naturalIdRegionAccessStrategy, + SessionFactoryImplementor factory, + Mapping cfg) { Class persisterClass = metadata.getCustomEntityPersisterClass(); if ( persisterClass == null ) { persisterClass = serviceRegistry.getService( PersisterClassResolver.class ).getEntityPersisterClass( metadata ); diff --git a/hibernate-core/src/main/java/org/hibernate/secure/spi/JaccIntegrator.java b/hibernate-core/src/main/java/org/hibernate/secure/spi/JaccIntegrator.java index 9d3c30af04..0584d4e213 100644 --- a/hibernate-core/src/main/java/org/hibernate/secure/spi/JaccIntegrator.java +++ b/hibernate-core/src/main/java/org/hibernate/secure/spi/JaccIntegrator.java @@ -35,6 +35,7 @@ import org.hibernate.event.service.spi.DuplicationStrategy; import org.hibernate.event.service.spi.EventListenerRegistry; import org.hibernate.event.spi.EventType; import org.hibernate.integrator.spi.Integrator; +import org.hibernate.integrator.spi.ServiceContributingIntegrator; import org.hibernate.metamodel.spi.MetadataImplementor; import org.hibernate.secure.internal.DisabledJaccServiceImpl; import org.hibernate.secure.internal.JaccPreDeleteEventListener; @@ -51,7 +52,7 @@ import org.hibernate.service.spi.SessionFactoryServiceRegistry; * * @author Steve Ebersole */ -public class JaccIntegrator implements ServiceContributor, Integrator { +public class JaccIntegrator implements ServiceContributingIntegrator { private static final Logger log = Logger.getLogger( JaccIntegrator.class ); private static final DuplicationStrategy DUPLICATION_STRATEGY = new DuplicationStrategy() { @@ -69,7 +70,7 @@ public class JaccIntegrator implements ServiceContributor, Integrator { @Override - public void contribute(StandardServiceRegistryBuilder serviceRegistryBuilder) { + public void prepareServices(StandardServiceRegistryBuilder serviceRegistryBuilder) { boolean isSecurityEnabled = serviceRegistryBuilder.getSettings().containsKey( AvailableSettings.JACC_ENABLED ); final JaccService jaccService = isSecurityEnabled ? new StandardJaccServiceImpl() : new DisabledJaccServiceImpl(); serviceRegistryBuilder.addService( JaccService.class, jaccService ); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/global/FetchProfileBinderTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/global/FetchProfileBinderTest.java index a01bcfd606..085f60f8b2 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/global/FetchProfileBinderTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/global/FetchProfileBinderTest.java @@ -26,6 +26,7 @@ package org.hibernate.metamodel.internal.source.annotations.global; import java.util.Iterator; import org.jboss.jandex.Index; +import org.jboss.jandex.IndexView; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -75,7 +76,7 @@ public class FetchProfileBinderTest extends BaseUnitTestCase { }) class Foo { } - Index index = JandexHelper.indexForClass( service, Foo.class ); + IndexView index = JandexHelper.indexForClass( service, Foo.class ); FetchProfileProcessor.bind( new AnnotationBindingContextImpl( meta, index ) ); @@ -90,7 +91,7 @@ public class FetchProfileBinderTest extends BaseUnitTestCase { @Test public void testFetchProfiles() { - Index index = JandexHelper.indexForClass( service, FooBar.class ); + IndexView index = JandexHelper.indexForClass( service, FooBar.class ); FetchProfileProcessor.bind( new AnnotationBindingContextImpl( meta, index ) ); Iterator mappedFetchProfiles = meta.getFetchProfiles().iterator(); @@ -126,7 +127,7 @@ public class FetchProfileBinderTest extends BaseUnitTestCase { }) class Foo { } - Index index = JandexHelper.indexForClass( service, Foo.class ); + IndexView index = JandexHelper.indexForClass( service, Foo.class ); FetchProfileProcessor.bind( new AnnotationBindingContextImpl( meta, index ) ); } diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/global/QueryBinderTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/global/QueryBinderTest.java index 229e565239..3c2547982c 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/global/QueryBinderTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/global/QueryBinderTest.java @@ -26,6 +26,7 @@ package org.hibernate.metamodel.internal.source.annotations.global; import javax.persistence.NamedNativeQuery; import org.jboss.jandex.Index; +import org.jboss.jandex.IndexView; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -72,7 +73,7 @@ public class QueryBinderTest extends BaseUnitTestCase { @NamedNativeQuery(name = "fubar", query = "SELECT * FROM FOO") class Foo { } - Index index = JandexHelper.indexForClass( service, Foo.class ); + IndexView index = JandexHelper.indexForClass( service, Foo.class ); QueryProcessor.bind( new AnnotationBindingContextImpl( meta, index ) ); } @@ -81,7 +82,7 @@ public class QueryBinderTest extends BaseUnitTestCase { @NamedNativeQuery(name = "fubar", query = "SELECT * FROM FOO", resultClass = Foo.class) class Foo { } - Index index = JandexHelper.indexForClass( service, Foo.class ); + IndexView index = JandexHelper.indexForClass( service, Foo.class ); QueryProcessor.bind( new AnnotationBindingContextImpl( meta, index ) ); NamedSQLQueryDefinition namedQuery = meta.getNamedNativeQuery( "fubar" ); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/util/BaseAnnotationIndexTestCase.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/util/BaseAnnotationIndexTestCase.java index 3f7430c561..caba23c773 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/util/BaseAnnotationIndexTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/util/BaseAnnotationIndexTestCase.java @@ -27,6 +27,7 @@ import java.util.Set; import javax.persistence.AccessType; import org.jboss.jandex.Index; +import org.jboss.jandex.IndexView; import org.junit.After; import org.junit.Before; @@ -58,7 +59,7 @@ public abstract class BaseAnnotationIndexTestCase extends BaseUnitTestCase { } public Set createEntityHierarchies(Class... clazz) { - Index index = JandexHelper.indexForClass( + IndexView index = JandexHelper.indexForClass( meta.getServiceRegistry().getService( ClassLoaderService.class ), clazz ); @@ -67,7 +68,7 @@ public abstract class BaseAnnotationIndexTestCase extends BaseUnitTestCase { } public EmbeddableHierarchy createEmbeddableHierarchy(AccessType accessType,SingularAttributeBinding.NaturalIdMutability naturalIdMutability, Class... configuredClasses) { - Index index = JandexHelper.indexForClass( + IndexView index = JandexHelper.indexForClass( meta.getServiceRegistry().getService( ClassLoaderService.class ), configuredClasses ); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/util/JandexHelperTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/util/JandexHelperTest.java index 164ed081a0..c9dba51a18 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/util/JandexHelperTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/util/JandexHelperTest.java @@ -23,6 +23,7 @@ */ package org.hibernate.metamodel.internal.source.annotations.util; +import java.util.Collection; import java.util.List; import java.util.Map; import javax.persistence.AttributeOverride; @@ -36,6 +37,7 @@ import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; import org.jboss.jandex.Index; +import org.jboss.jandex.IndexView; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -81,7 +83,7 @@ public class JandexHelperTest extends BaseUnitTestCase { private String bar; private String fubar; } - Index index = JandexHelper.indexForClass( classLoaderService, Foo.class ); + IndexView index = JandexHelper.indexForClass( classLoaderService, Foo.class ); ClassInfo classInfo = index.getClassByName( DotName.createSimple( Foo.class.getName() ) ); Map> memberAnnotations = JandexHelper.getMemberAnnotations( @@ -106,10 +108,10 @@ public class JandexHelperTest extends BaseUnitTestCase { class Foo { } - Index index = JandexHelper.indexForClass( classLoaderService, Foo.class ); - List annotationInstances = index.getAnnotations( JPADotNames.ATTRIBUTE_OVERRIDE ); + IndexView index = JandexHelper.indexForClass( classLoaderService, Foo.class ); + Collection annotationInstances = index.getAnnotations( JPADotNames.ATTRIBUTE_OVERRIDE ); assertTrue( annotationInstances.size() == 1 ); - AnnotationInstance annotationInstance = annotationInstances.get( 0 ); + AnnotationInstance annotationInstance = annotationInstances.iterator().next(); // try to retrieve the name String name = JandexHelper.getValue( annotationInstance, "name", String.class ); @@ -135,10 +137,10 @@ public class JandexHelperTest extends BaseUnitTestCase { class Foo { } - Index index = JandexHelper.indexForClass( classLoaderService, Foo.class ); - List annotationInstances = index.getAnnotations( JPADotNames.ATTRIBUTE_OVERRIDE ); + IndexView index = JandexHelper.indexForClass( classLoaderService, Foo.class ); + Collection annotationInstances = index.getAnnotations( JPADotNames.ATTRIBUTE_OVERRIDE ); assertTrue( annotationInstances.size() == 1 ); - AnnotationInstance annotationInstance = annotationInstances.get( 0 ); + AnnotationInstance annotationInstance = annotationInstances.iterator().next(); JandexHelper.getValue( annotationInstance, "name", Float.class ); } @@ -149,10 +151,10 @@ public class JandexHelperTest extends BaseUnitTestCase { class Foo { } - Index index = JandexHelper.indexForClass( classLoaderService, Foo.class ); - List annotationInstances = index.getAnnotations( JPADotNames.NAMED_QUERY ); + IndexView index = JandexHelper.indexForClass( classLoaderService, Foo.class ); + Collection annotationInstances = index.getAnnotations( JPADotNames.NAMED_QUERY ); assertTrue( annotationInstances.size() == 1 ); - AnnotationInstance annotationInstance = annotationInstances.get( 0 ); + AnnotationInstance annotationInstance = annotationInstances.iterator().next(); LockModeType lockMode = JandexHelper.getEnumValue( annotationInstance, "lockMode", LockModeType.class ); assertEquals( "Wrong lock mode", LockModeType.NONE, lockMode ); @@ -164,10 +166,10 @@ public class JandexHelperTest extends BaseUnitTestCase { class Foo { } - Index index = JandexHelper.indexForClass( classLoaderService, Foo.class ); - List annotationInstances = index.getAnnotations( JPADotNames.NAMED_QUERY ); + IndexView index = JandexHelper.indexForClass( classLoaderService, Foo.class ); + Collection annotationInstances = index.getAnnotations( JPADotNames.NAMED_QUERY ); assertTrue( annotationInstances.size() == 1 ); - AnnotationInstance annotationInstance = annotationInstances.get( 0 ); + AnnotationInstance annotationInstance = annotationInstances.iterator().next(); LockModeType lockMode = JandexHelper.getEnumValue( annotationInstance, "lockMode", LockModeType.class ); assertEquals( "Wrong lock mode", LockModeType.OPTIMISTIC, lockMode ); @@ -180,10 +182,10 @@ public class JandexHelperTest extends BaseUnitTestCase { private String foo; } - Index index = JandexHelper.indexForClass( classLoaderService, Foo.class ); - List annotationInstances = index.getAnnotations( HibernateDotNames.INDEX ); + IndexView index = JandexHelper.indexForClass( classLoaderService, Foo.class ); + Collection annotationInstances = index.getAnnotations( HibernateDotNames.INDEX ); assertTrue( annotationInstances.size() == 1 ); - AnnotationInstance annotationInstance = annotationInstances.get( 0 ); + AnnotationInstance annotationInstance = annotationInstances.iterator().next(); String[] columnNames = JandexHelper.getValue( annotationInstance, "columnNames", String[].class ); Assert.assertTrue( columnNames.length == 3 ); @@ -195,10 +197,10 @@ public class JandexHelperTest extends BaseUnitTestCase { class Foo { } - Index index = JandexHelper.indexForClass( classLoaderService, Foo.class ); - List annotationInstances = index.getAnnotations( HibernateDotNames.NAMED_NATIVE_QUERY ); + IndexView index = JandexHelper.indexForClass( classLoaderService, Foo.class ); + Collection annotationInstances = index.getAnnotations( HibernateDotNames.NAMED_NATIVE_QUERY ); assertTrue( annotationInstances.size() == 1 ); - AnnotationInstance annotationInstance = annotationInstances.get( 0 ); + AnnotationInstance annotationInstance = annotationInstances.iterator().next(); JandexHelper.getValue( annotationInstance, "resultClass", Class.class ); } @@ -209,10 +211,10 @@ public class JandexHelperTest extends BaseUnitTestCase { class Foo { } - Index index = JandexHelper.indexForClass( classLoaderService, Foo.class ); - List annotationInstances = index.getAnnotations( HibernateDotNames.NAMED_NATIVE_QUERY ); + IndexView index = JandexHelper.indexForClass( classLoaderService, Foo.class ); + Collection annotationInstances = index.getAnnotations( HibernateDotNames.NAMED_NATIVE_QUERY ); assertTrue( annotationInstances.size() == 1 ); - AnnotationInstance annotationInstance = annotationInstances.get( 0 ); + AnnotationInstance annotationInstance = annotationInstances.iterator().next(); String fqcn = JandexHelper.getValue( annotationInstance, "resultClass", String.class ); assertEquals( "Wrong class names", Foo.class.getName(), fqcn ); @@ -224,10 +226,10 @@ public class JandexHelperTest extends BaseUnitTestCase { class Foo { } - Index index = JandexHelper.indexForClass( classLoaderService, Foo.class ); - List annotationInstances = index.getAnnotations( JPADotNames.ENTITY ); + IndexView index = JandexHelper.indexForClass( classLoaderService, Foo.class ); + Collection annotationInstances = index.getAnnotations( JPADotNames.ENTITY ); assertTrue( annotationInstances.size() == 1 ); - AnnotationInstance annotationInstance = annotationInstances.get( 0 ); + AnnotationInstance annotationInstance = annotationInstances.iterator().next(); try { JandexHelper.getValue( annotationInstance, "foo", String.class ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/idmanytoone/IdManyToOneTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/idmanytoone/IdManyToOneTest.java index 9e0af94fbc..45edeb9dd0 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/idmanytoone/IdManyToOneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/idmanytoone/IdManyToOneTest.java @@ -29,6 +29,7 @@ import org.hibernate.Criteria; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.criterion.Restrictions; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; @@ -37,6 +38,7 @@ import static org.junit.Assert.assertEquals; /** * @author Emmanuel Bernard */ +@FailureExpectedWithNewMetamodel public class IdManyToOneTest extends BaseCoreFunctionalTestCase { @Test public void testFkCreationOrdering() throws Exception { diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/ExplicitSqlResultSetMappingTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/ExplicitSqlResultSetMappingTest.java index 6cbb4aea0d..c9d7d2357a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/ExplicitSqlResultSetMappingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/ExplicitSqlResultSetMappingTest.java @@ -28,13 +28,11 @@ import org.junit.Test; import org.hibernate.Session; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; /** * @author Steve Ebersole */ -@FailureExpectedWithNewMetamodel public class ExplicitSqlResultSetMappingTest extends BaseCoreFunctionalTestCase { private String queryString = null; diff --git a/hibernate-core/src/test/java/org/hibernate/test/cache/InsertedDataTest.java b/hibernate-core/src/test/java/org/hibernate/test/cache/InsertedDataTest.java index 5e8693e999..d8dd69cda3 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/cache/InsertedDataTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/cache/InsertedDataTest.java @@ -58,7 +58,7 @@ public class InsertedDataTest extends BaseCoreFunctionalTestCase { } @Override - protected void prepareBasicRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) { + protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) { serviceRegistryBuilder.applySetting( Environment.CACHE_REGION_PREFIX, "" ); serviceRegistryBuilder.applySetting( Environment.GENERATE_STATISTICS, "true" ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/event/collection/detached/MergeCollectionEventTest.java b/hibernate-core/src/test/java/org/hibernate/test/event/collection/detached/MergeCollectionEventTest.java index f065e5fe04..541444e2a7 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/event/collection/detached/MergeCollectionEventTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/event/collection/detached/MergeCollectionEventTest.java @@ -64,8 +64,8 @@ public class MergeCollectionEventTest extends BaseCoreFunctionalTestCase { } @Override - protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) { - super.prepareBootstrapRegistryBuilder( builder ); + protected void prepareBootstrapServiceRegistryBuilder(BootstrapServiceRegistryBuilder builder) { + super.prepareBootstrapServiceRegistryBuilder( builder ); builder.with( collectionListenerIntegrator ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/events/CallbackTest.java b/hibernate-core/src/test/java/org/hibernate/test/events/CallbackTest.java index 94e1f4f030..1f17c9bf49 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/events/CallbackTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/events/CallbackTest.java @@ -54,19 +54,14 @@ public class CallbackTest extends BaseCoreFunctionalTestCase { private TestingObserver observer = new TestingObserver(); private TestingListener listener = new TestingListener(); - @Override - public String[] getMappings() { - return NO_MAPPINGS; - } - @Override public void configure(Configuration cfg) { cfg.setSessionFactoryObserver( observer ); } @Override - protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) { - super.prepareBootstrapRegistryBuilder( builder ); + protected void prepareBootstrapServiceRegistryBuilder(BootstrapServiceRegistryBuilder builder) { + super.prepareBootstrapServiceRegistryBuilder( builder ); builder.with( new Integrator() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/fileimport/CommandExtractorServiceTest.java b/hibernate-core/src/test/java/org/hibernate/test/fileimport/CommandExtractorServiceTest.java index 793749f250..6555c8d74e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/fileimport/CommandExtractorServiceTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/fileimport/CommandExtractorServiceTest.java @@ -47,8 +47,8 @@ public class CommandExtractorServiceTest extends MultiLineImportFileTest { } @Override - protected void prepareBasicRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) { - super.prepareBasicRegistryBuilder( serviceRegistryBuilder ); + protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) { + super.prepareStandardServiceRegistryBuilder( serviceRegistryBuilder ); serviceRegistryBuilder.addService( ImportSqlCommandExtractor.class, new MultipleLinesSqlCommandExtractor() ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/fileimport/MultiLineImportFileTest.java b/hibernate-core/src/test/java/org/hibernate/test/fileimport/MultiLineImportFileTest.java index 9907a864b0..aaf5ebd930 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/fileimport/MultiLineImportFileTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/fileimport/MultiLineImportFileTest.java @@ -58,11 +58,6 @@ public class MultiLineImportFileTest extends BaseCoreFunctionalTestCase { ); } - @Override - public String[] getMappings() { - return NO_MAPPINGS; - } - @Test public void testImportFile() throws Exception { Session s = openSession(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/flush/TestAutoFlushBeforeQueryExecution.java b/hibernate-core/src/test/java/org/hibernate/test/flush/TestAutoFlushBeforeQueryExecution.java index 10b8fcc404..e3495fa156 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/flush/TestAutoFlushBeforeQueryExecution.java +++ b/hibernate-core/src/test/java/org/hibernate/test/flush/TestAutoFlushBeforeQueryExecution.java @@ -225,8 +225,8 @@ public class TestAutoFlushBeforeQueryExecution extends BaseCoreFunctionalTestCas } @Override - protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) { - super.prepareBootstrapRegistryBuilder( builder ); + protected void prepareBootstrapServiceRegistryBuilder(BootstrapServiceRegistryBuilder builder) { + super.prepareBootstrapServiceRegistryBuilder( builder ); builder.with( new Integrator() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/flush/TestCollectionInitializingDuringFlush.java b/hibernate-core/src/test/java/org/hibernate/test/flush/TestCollectionInitializingDuringFlush.java index f120d2b017..2933ebf228 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/flush/TestCollectionInitializingDuringFlush.java +++ b/hibernate-core/src/test/java/org/hibernate/test/flush/TestCollectionInitializingDuringFlush.java @@ -88,8 +88,8 @@ public class TestCollectionInitializingDuringFlush extends BaseCoreFunctionalTes } @Override - protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) { - super.prepareBootstrapRegistryBuilder( builder ); + protected void prepareBootstrapServiceRegistryBuilder(BootstrapServiceRegistryBuilder builder) { + super.prepareBootstrapServiceRegistryBuilder( builder ); builder.with( new Integrator() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/AbstractJPATest.java b/hibernate-core/src/test/java/org/hibernate/test/jpa/AbstractJPATest.java index f3bcb7d636..33cfad2bb3 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jpa/AbstractJPATest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jpa/AbstractJPATest.java @@ -69,7 +69,7 @@ public abstract class AbstractJPATest extends BaseCoreFunctionalTestCase { } @Override - protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) { + protected void prepareBootstrapServiceRegistryBuilder(BootstrapServiceRegistryBuilder builder) { builder.with( new Integrator() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/bidir/component/EagerKeyManyToOneTest.java b/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/bidir/component/EagerKeyManyToOneTest.java index d754a656ac..f91b448ea0 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/bidir/component/EagerKeyManyToOneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/bidir/component/EagerKeyManyToOneTest.java @@ -62,8 +62,8 @@ public class EagerKeyManyToOneTest extends BaseCoreFunctionalTestCase { } @Override - protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) { - super.prepareBootstrapRegistryBuilder( builder ); + protected void prepareBootstrapServiceRegistryBuilder(BootstrapServiceRegistryBuilder builder) { + super.prepareBootstrapServiceRegistryBuilder( builder ); builder.with( new Integrator() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/onetoone/joined/JoinedSubclassOneToOneTest.java b/hibernate-core/src/test/java/org/hibernate/test/onetoone/joined/JoinedSubclassOneToOneTest.java index 0f16451a60..2effa8d85b 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/onetoone/joined/JoinedSubclassOneToOneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/onetoone/joined/JoinedSubclassOneToOneTest.java @@ -32,7 +32,6 @@ import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.stat.EntityStatistics; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import static org.junit.Assert.assertEquals; diff --git a/hibernate-core/src/test/java/org/hibernate/test/onetoone/link/OneToOneLinkTest.java b/hibernate-core/src/test/java/org/hibernate/test/onetoone/link/OneToOneLinkTest.java index a49dd9a9f1..379d100cfa 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/onetoone/link/OneToOneLinkTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/onetoone/link/OneToOneLinkTest.java @@ -30,7 +30,6 @@ import org.junit.Test; import org.hibernate.Hibernate; import org.hibernate.Session; import org.hibernate.Transaction; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import static org.junit.Assert.assertEquals; diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/AvailableSettings.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/AvailableSettings.java index 63ee15a62d..1c51093bde 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/AvailableSettings.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/AvailableSettings.java @@ -24,8 +24,6 @@ package org.hibernate.jpa; -import org.hibernate.internal.util.StringHelper; - /** * Defines the available HEM settings, both JPA-defined as well as Hibernate-specific *

diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/ClassDescriptorImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/ClassDescriptorImpl.java index f8d15c1419..2f49ffc8e4 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/ClassDescriptorImpl.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/ClassDescriptorImpl.java @@ -23,6 +23,8 @@ */ package org.hibernate.jpa.boot.internal; +import java.net.URL; + import org.hibernate.jpa.boot.spi.ClassDescriptor; import org.hibernate.jpa.boot.spi.InputStreamAccess; @@ -38,6 +40,12 @@ public class ClassDescriptorImpl implements ClassDescriptor { this.streamAccess = streamAccess; } + public ClassDescriptorImpl(final Class clazz){ + this.name = clazz.getName(); + final URL url = clazz.getClassLoader().getResource( name.replace( '.', '/' ) + ".class" ); + this.streamAccess = new UrlInputStreamAccess( url ); + } + @Override public String getName() { return name; diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java index 38a37c0861..c2c621e427 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java @@ -40,7 +40,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; @@ -65,23 +64,26 @@ import org.hibernate.SessionFactory; import org.hibernate.SessionFactoryObserver; import org.hibernate.boot.registry.BootstrapServiceRegistry; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; +import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.internal.ConfigLoader; import org.hibernate.boot.registry.selector.spi.StrategySelector; import org.hibernate.boot.spi.CacheRegionDefinition; -import org.hibernate.boot.spi.JaccDefinition; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.cfg.NamingStrategy; +import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.cfg.beanvalidation.BeanValidationIntegrator; +import org.hibernate.engine.config.spi.ConfigurationService; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory; import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory; import org.hibernate.id.factory.spi.MutableIdentifierGeneratorFactory; import org.hibernate.integrator.spi.Integrator; import org.hibernate.internal.util.StringHelper; +import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.jaxb.spi.cfg.JaxbHibernateConfiguration; import org.hibernate.jaxb.spi.cfg.JaxbHibernateConfiguration.JaxbSessionFactory.JaxbMapping; import org.hibernate.internal.util.ValueHolder; @@ -106,9 +108,12 @@ import org.hibernate.jpa.boot.scan.spi.ScanOptions; import org.hibernate.jpa.boot.scan.spi.ScanResult; import org.hibernate.jpa.boot.scan.spi.Scanner; import org.hibernate.jpa.spi.IdentifierGeneratorStrategyProvider; -import org.hibernate.metamodel.MetadataSources; +import org.hibernate.metamodel.Metadata; +import org.hibernate.metamodel.MetadataBuilder; +import org.hibernate.metamodel.SessionFactoryBuilder; import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; +import org.hibernate.metamodel.spi.MetadataImplementor; import org.hibernate.proxy.EntityNotFoundDelegate; import org.hibernate.secure.spi.GrantedPermission; import org.hibernate.secure.spi.JaccService; @@ -161,12 +166,16 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil private NamingStrategy namingStrategy; private SessionFactoryObserver suppliedSessionFactoryObserver; - private MetadataSources metadataSources; + private MetadataSources mockMetadataSources; + private org.hibernate.metamodel.MetadataSources metadataSources; private Configuration hibernateConfiguration; private static EntityNotFoundDelegate jpaEntityNotFoundDelegate = new JpaEntityNotFoundDelegate(); private ClassLoader providedClassLoader; + private final IndexView jandexIndex; + + private final boolean usingNewMetadata; private static class JpaEntityNotFoundDelegate implements EntityNotFoundDelegate, Serializable { public void handleEntityNotFound(String entityName, Serializable id) { @@ -204,16 +213,28 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil this.configurationValues = mergePropertySources( persistenceUnit, integrationSettings, bootstrapServiceRegistry ); // add all merged configuration values into the service registry builder this.serviceRegistryBuilder.applySettings( configurationValues ); + if ( configurationValues.containsKey( org.hibernate.metamodel.MetadataSources.USE_NEW_METADATA_MAPPINGS ) ) { + String value = (String)configurationValues.get( org.hibernate.metamodel.MetadataSources.USE_NEW_METADATA_MAPPINGS); + this.usingNewMetadata = Boolean.valueOf( value ); + } + else { + this.usingNewMetadata = true; + } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Next we do a preliminary pass at metadata processing, which involves: // 1) scanning final ScanResult scanResult = scan( bootstrapServiceRegistry ); final DeploymentResources deploymentResources = buildDeploymentResources( scanResult, bootstrapServiceRegistry ); // 2) building a Jandex index - final IndexView jandexIndex = locateOrBuildJandexIndex( deploymentResources ); + this.jandexIndex = locateOrBuildJandexIndex( deploymentResources ); // 3) building "metadata sources" to keep for later to use in building the SessionFactory - metadataSources = prepareMetadataSources( jandexIndex, deploymentResources, bootstrapServiceRegistry ); + if ( usingNewMetadata ) { + metadataSources = prepareMetadataSources( deploymentResources, bootstrapServiceRegistry ); + } + else { + mockMetadataSources = prepareMetadataSources( jandexIndex, deploymentResources ); + } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ withValidatorFactory( configurationValues.get( AvailableSettings.VALIDATION_FACTORY ) ); @@ -223,7 +244,12 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil // container situations, calling back into PersistenceUnitInfo#addClassTransformer final boolean useClassTransformer = "true".equals( configurationValues.remove( AvailableSettings.USE_CLASS_ENHANCER ) ); if ( useClassTransformer ) { - persistenceUnit.pushClassTransformer( metadataSources.collectMappingClassNames() ); + if ( !usingNewMetadata ) { + persistenceUnit.pushClassTransformer( mockMetadataSources.collectMappingClassNames() ); + } + else { + throw new NotYetImplementedException( "The new JPA class enhancer is not supported in metamodel yet" ); + } } } @@ -272,8 +298,28 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil } final List explicitClassNames = persistenceUnit.getManagedClassNames(); + List classNames = new ArrayList(); if ( explicitClassNames != null ) { - for ( String explicitClassName : explicitClassNames ) { + classNames.addAll( explicitClassNames ); + } + for ( JaxbHibernateConfiguration.JaxbSessionFactory.JaxbMapping jaxbMapping : cfgXmlNamedMappings ) { + if ( jaxbMapping.getClazz() != null ) { + classNames.add( jaxbMapping.getClazz() ); + } + + else if ( jaxbMapping.getPackage() != null ) { + classNames.add( jaxbMapping.getPackage() ); + } + } + List loadedAnnotatedClasses = (List) configurationValues.remove( AvailableSettings.LOADED_CLASSES ); + if ( loadedAnnotatedClasses != null ) { + for ( Class cls : loadedAnnotatedClasses ) { + classNames.add( cls.getName() ); + } + } + + + for ( String explicitClassName : classNames ) { // IMPL NOTE : explicitClassNames can contain class or package names!!! if ( classDescriptorMap.containsKey( explicitClassName ) ) { continue; @@ -312,7 +358,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil persistenceUnit.getName() ); } - } + return new DeploymentResources() { @Override @@ -354,13 +400,45 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil return hibernateConfiguration; } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + private org.hibernate.metamodel.MetadataSources prepareMetadataSources( + DeploymentResources deploymentResources, + BootstrapServiceRegistry bootstrapServiceRegistry) { + org.hibernate.metamodel.MetadataSources ms = new org.hibernate.metamodel.MetadataSources( + bootstrapServiceRegistry + ); +// for(ClassDescriptor classDescriptor : deploymentResources.getClassDescriptors()){ +// final String className = classDescriptor.getName(); +// ms.addAnnotatedClassName( className ); +// } +// +// for ( PackageDescriptor packageDescriptor : deploymentResources.getPackageDescriptors() ) { +// ms.addPackage( packageDescriptor.getName() ); +// } + for ( MappingFileDescriptor mappingFileDescriptor : deploymentResources.getMappingFileDescriptors() ) { + ms.addInputStream( mappingFileDescriptor.getStreamAccess().accessInputStream() ); + } + + final String explicitHbmXmls = (String) configurationValues.remove( AvailableSettings.HBXML_FILES ); + if ( StringHelper.isNotEmpty( explicitHbmXmls ) ) { + for ( String fileName : StringHelper.split( ", ", explicitHbmXmls ) ) { + ms.addInputStream( bootstrapServiceRegistry.getService( ClassLoaderService.class ).locateResourceStream( fileName )); + } + } + + final List explicitOrmXml = (List) configurationValues.remove( AvailableSettings.XML_FILE_NAMES ); + if ( explicitOrmXml != null ) { + for ( String fileName : explicitOrmXml ) { + ms.addInputStream( bootstrapServiceRegistry.getService( ClassLoaderService.class ).locateResourceStream( fileName )); + } + } + return ms; + } @SuppressWarnings("unchecked") private MetadataSources prepareMetadataSources( IndexView jandexIndex, - DeploymentResources deploymentResources, - BootstrapServiceRegistry bootstrapServiceRegistry) { + DeploymentResources deploymentResources) { // todo : this needs to tie into the metamodel branch... MetadataSources metadataSources = new MetadataSources(); @@ -565,14 +643,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil } // was getting NPE exceptions from the underlying map when just using #putAll, so going this safer route... - Iterator itr = merged.entrySet().iterator(); - while ( itr.hasNext() ) { - final Map.Entry entry = (Map.Entry) itr.next(); - if ( entry.getValue() == null ) { - itr.remove(); - } - } - + CollectionHelper.cleanUpNullValue( merged ); return merged; } @@ -601,7 +672,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil = (JaxbHibernateConfiguration.JaxbSessionFactory.JaxbClassCache) cacheDeclaration; cacheRegionDefinitions.add( new CacheRegionDefinition( - CacheRegionDefinition.CacheType.ENTITY, + CacheRegionDefinition.CacheRegionType.ENTITY, jaxbClassCache.getClazz(), jaxbClassCache.getUsage().value(), jaxbClassCache.getRegion(), @@ -614,7 +685,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil = (JaxbHibernateConfiguration.JaxbSessionFactory.JaxbCollectionCache) cacheDeclaration; cacheRegionDefinitions.add( new CacheRegionDefinition( - CacheRegionDefinition.CacheType.COLLECTION, + CacheRegionDefinition.CacheRegionType.COLLECTION, jaxbCollectionCache.getCollection(), jaxbCollectionCache.getUsage().value(), jaxbCollectionCache.getRegion(), @@ -695,11 +766,11 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil } } - private void addCacheRegionDefinition(String role, String value, CacheRegionDefinition.CacheType cacheType) { + private void addCacheRegionDefinition(String role, String value, CacheRegionDefinition.CacheRegionType cacheType) { final StringTokenizer params = new StringTokenizer( value, ";, " ); if ( !params.hasMoreTokens() ) { StringBuilder error = new StringBuilder( "Illegal usage of " ); - if ( cacheType == CacheRegionDefinition.CacheType.ENTITY ) { + if ( cacheType == CacheRegionDefinition.CacheRegionType.ENTITY ) { error.append( AvailableSettings.CLASS_CACHE_PREFIX ) .append( ": " ) .append( AvailableSettings.CLASS_CACHE_PREFIX ); @@ -723,7 +794,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil region = params.nextToken(); } boolean lazyProperty = true; - if ( cacheType == CacheRegionDefinition.CacheType.ENTITY ) { + if ( cacheType == CacheRegionDefinition.CacheRegionType.ENTITY ) { if ( params.hasMoreTokens() ) { lazyProperty = "all".equalsIgnoreCase( params.nextToken() ); } @@ -841,48 +912,117 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil } @SuppressWarnings("unchecked") + @Override public EntityManagerFactory build() { processProperties(); - final ServiceRegistry serviceRegistry = buildServiceRegistry(); + final StandardServiceRegistry serviceRegistry = buildServiceRegistry(); final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class ); // IMPL NOTE : TCCL handling here is temporary. // It is needed because this code still uses Hibernate Configuration and Hibernate commons-annotations // in turn which relies on TCCL being set. + if ( usingNewMetadata ) { + final JaccService jaccService = serviceRegistry.getService( JaccService.class ); + for ( GrantedPermission grantedPermission : grantedJaccPermissions ) { + jaccService.addPermission( grantedPermission ); + } - return ( (ClassLoaderServiceImpl) classLoaderService ).withTccl( - new ClassLoaderServiceImpl.Work() { - @Override - public EntityManagerFactoryImpl perform() { - hibernateConfiguration = buildHibernateConfiguration( serviceRegistry ); + final Object strategyProviderValue = configurationValues.get( AvailableSettings.IDENTIFIER_GENERATOR_STRATEGY_PROVIDER ); + final IdentifierGeneratorStrategyProvider strategyProvider = strategyProviderValue == null + ? null + : serviceRegistry.getService( StrategySelector.class ) + .resolveStrategy( IdentifierGeneratorStrategyProvider.class, strategyProviderValue ); - SessionFactoryImplementor sessionFactory; - try { - sessionFactory = (SessionFactoryImplementor) hibernateConfiguration.buildSessionFactory( - serviceRegistry + if ( strategyProvider != null ) { + for ( Map.Entry> entry : strategyProvider.getStrategies().entrySet() ) { + serviceRegistry.getService( MutableIdentifierGeneratorFactory.class ).register( entry.getKey(), entry.getValue() ); + } + } + + metadataSources.addCacheRegionDefinitions( cacheRegionDefinitions ); + for ( JaxbHibernateConfiguration.JaxbSessionFactory.JaxbMapping jaxbMapping : cfgXmlNamedMappings ) { + if ( jaxbMapping.getResource() != null ) { + metadataSources.addResource( jaxbMapping.getResource() ); + } + else if ( jaxbMapping.getJar() != null ) { + metadataSources.addJar( new File( jaxbMapping.getJar() ) ); + } + } + + + + MetadataBuilder builder = metadataSources.getMetadataBuilder( serviceRegistry ); + builder.with( jandexIndex ); + if ( namingStrategy != null ) { + builder.with( namingStrategy ); + } + + MetadataImplementor metadata = (MetadataImplementor)builder.build(); + + + SessionFactoryBuilder sfBuilder = metadata.getSessionFactoryBuilder(); + sfBuilder.with( jpaEntityNotFoundDelegate ); + if ( sessionFactoryInterceptor != null ) { + sfBuilder.with( sessionFactoryInterceptor ); + } + + + if ( suppliedSessionFactoryObserver != null ) { + sfBuilder.add( suppliedSessionFactoryObserver ); + } + sfBuilder.add( new ServiceRegistryCloser() ); + + SessionFactoryImplementor sessionFactory; + try { + sessionFactory = (SessionFactoryImplementor) sfBuilder.build(); + } + catch ( MappingException e ) { + throw persistenceException( "Unable to build Hibernate SessionFactory", e ); + } + + return new EntityManagerFactoryImpl( + persistenceUnit.getName(), + sessionFactory, + settings, + configurationValues, + serviceRegistry.getService( ConfigurationService.class ).getSettings() + ); + } + else { + return ( (ClassLoaderServiceImpl) classLoaderService ).withTccl( + new ClassLoaderServiceImpl.Work() { + @Override + public EntityManagerFactoryImpl perform() { + hibernateConfiguration = buildHibernateConfiguration( serviceRegistry ); + + SessionFactoryImplementor sessionFactory; + try { + sessionFactory = (SessionFactoryImplementor) hibernateConfiguration.buildSessionFactory( + serviceRegistry + ); + } + catch ( MappingException e ) { + throw persistenceException( "Unable to build Hibernate SessionFactory", e ); + } + + if ( suppliedSessionFactoryObserver != null ) { + sessionFactory.addObserver( suppliedSessionFactoryObserver ); + } + sessionFactory.addObserver( new ServiceRegistryCloser() ); + + // NOTE : passing cfg is temporary until + return new EntityManagerFactoryImpl( + persistenceUnit.getName(), + sessionFactory, + settings, + configurationValues, + hibernateConfiguration ); } - catch (MappingException e) { - throw persistenceException( "Unable to build Hibernate SessionFactory", e ); - } - - if ( suppliedSessionFactoryObserver != null ) { - sessionFactory.addObserver( suppliedSessionFactoryObserver ); - } - sessionFactory.addObserver( new ServiceRegistryCloser() ); - - // NOTE : passing cfg is temporary until - return new EntityManagerFactoryImpl( - persistenceUnit.getName(), - sessionFactory, - settings, - configurationValues, - hibernateConfiguration - ); } - } - ); + ); + } } private void processProperties() { @@ -932,14 +1072,14 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil addCacheRegionDefinition( keyString.substring( AvailableSettings.CLASS_CACHE_PREFIX.length() + 1 ), (String) entry.getValue(), - CacheRegionDefinition.CacheType.ENTITY + CacheRegionDefinition.CacheRegionType.ENTITY ); } else if ( keyString.startsWith( AvailableSettings.COLLECTION_CACHE_PREFIX ) ) { addCacheRegionDefinition( keyString.substring( AvailableSettings.COLLECTION_CACHE_PREFIX.length() + 1 ), (String) entry.getValue(), - CacheRegionDefinition.CacheType.COLLECTION + CacheRegionDefinition.CacheRegionType.COLLECTION ); } else if ( keyString.startsWith( AvailableSettings.JACC_PREFIX ) @@ -1018,7 +1158,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil : strategySelector.selectStrategyImplementor( Interceptor.class, value.toString() ); } - public ServiceRegistry buildServiceRegistry() { + public StandardServiceRegistry buildServiceRegistry() { return serviceRegistryBuilder.build(); } @@ -1058,19 +1198,19 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil if ( cacheRegionDefinitions != null ) { for ( CacheRegionDefinition cacheRegionDefinition : cacheRegionDefinitions ) { - if ( cacheRegionDefinition.cacheType == CacheRegionDefinition.CacheType.ENTITY ) { + if ( cacheRegionDefinition.getRegionType() == CacheRegionDefinition.CacheRegionType.ENTITY ) { cfg.setCacheConcurrencyStrategy( - cacheRegionDefinition.role, - cacheRegionDefinition.usage, - cacheRegionDefinition.region, - cacheRegionDefinition.cacheLazy + cacheRegionDefinition.getRole(), + cacheRegionDefinition.getUsage(), + cacheRegionDefinition.getRegion(), + cacheRegionDefinition.isCacheLazy() ); } else { cfg.setCollectionCacheConcurrencyStrategy( - cacheRegionDefinition.role, - cacheRegionDefinition.usage, - cacheRegionDefinition.region + cacheRegionDefinition.getRole(), + cacheRegionDefinition.getUsage(), + cacheRegionDefinition.getRegion() ); } } @@ -1080,34 +1220,19 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil // todo : need to have this use the metamodel codebase eventually... for ( JaxbMapping jaxbMapping : cfgXmlNamedMappings ) { - if ( jaxbMapping.getClazz() != null ) { - cfg.addAnnotatedClass( - serviceRegistry.getService( ClassLoaderService.class ).classForName( jaxbMapping.getClazz() ) - ); - } - else if ( jaxbMapping.getResource() != null ) { + if ( jaxbMapping.getResource() != null ) { cfg.addResource( jaxbMapping.getResource() ); } else if ( jaxbMapping.getJar() != null ) { cfg.addJar( new File( jaxbMapping.getJar() ) ); } - else if ( jaxbMapping.getPackage() != null ) { - cfg.addPackage( jaxbMapping.getPackage() ); - } } - List loadedAnnotatedClasses = (List) configurationValues.remove( AvailableSettings.LOADED_CLASSES ); - if ( loadedAnnotatedClasses != null ) { - for ( Class cls : loadedAnnotatedClasses ) { - cfg.addAnnotatedClass( cls ); - } - } - - for ( String className : metadataSources.getAnnotatedMappingClassNames() ) { + for ( String className : mockMetadataSources.getAnnotatedMappingClassNames() ) { cfg.addAnnotatedClass( serviceRegistry.getService( ClassLoaderService.class ).classForName( className ) ); } - for ( MetadataSources.ConverterDescriptor converterDescriptor : metadataSources.getConverterDescriptors() ) { + for ( MetadataSources.ConverterDescriptor converterDescriptor : mockMetadataSources.getConverterDescriptors() ) { final Class converterClass; try { Class theClass = serviceRegistry.getService( ClassLoaderService.class ).classForName( converterDescriptor.converterClassName ); @@ -1124,7 +1249,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil cfg.addAttributeConverter( converterClass, converterDescriptor.autoApply ); } - for ( String resourceName : metadataSources.mappingFileResources ) { + for ( String resourceName : mockMetadataSources.mappingFileResources ) { Boolean useMetaInf = null; try { if ( resourceName.endsWith( META_INF_ORM_XML ) ) { @@ -1152,7 +1277,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil LOG.exceptionHeaderNotFound( getExceptionHeader(), META_INF_ORM_XML ); } } - for ( NamedInputStream namedInputStream : metadataSources.namedMappingFileInputStreams ) { + for ( NamedInputStream namedInputStream : mockMetadataSources.namedMappingFileInputStreams ) { try { //addInputStream has the responsibility to close the stream cfg.addInputStream( new BufferedInputStream( namedInputStream.getStream() ) ); @@ -1181,7 +1306,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil } } } - for ( String packageName : metadataSources.packageNames ) { + for ( String packageName : mockMetadataSources.packageNames ) { cfg.addPackage( packageName ); } return cfg; @@ -1217,41 +1342,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil return "[PersistenceUnit: " + persistenceUnit.getName() + "] "; } - public static class CacheRegionDefinition { - public static enum CacheType { ENTITY, COLLECTION } - public final CacheType cacheType; - public final String role; - public final String usage; - public final String region; - public final boolean cacheLazy; - - public CacheRegionDefinition( - CacheType cacheType, - String role, - String usage, - String region, boolean cacheLazy) { - this.cacheType = cacheType; - this.role = role; - this.usage = usage; - this.region = region; - this.cacheLazy = cacheLazy; - } - } - - public static class JaccDefinition { - public final String contextId; - public final String role; - public final String clazz; - public final String actions; - - public JaccDefinition(String contextId, String role, String clazz, String actions) { - this.contextId = contextId; - this.role = role; - this.clazz = clazz; - this.actions = actions; - } - } public static class MetadataSources { private final List annotatedMappingClassNames = new ArrayList(); diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/EntityManagerFactoryImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/EntityManagerFactoryImpl.java index 585f58e8d1..81cd2f7a2b 100755 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/EntityManagerFactoryImpl.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/EntityManagerFactoryImpl.java @@ -46,6 +46,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; import org.jboss.logging.Logger; @@ -121,6 +122,15 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory { SettingsImpl settings, Map configurationValues, Configuration cfg) { + this(persistenceUnitName, sessionFactory, settings, configurationValues, cfg.getProperties() ); + } + + public EntityManagerFactoryImpl( + String persistenceUnitName, + SessionFactoryImplementor sessionFactory, + SettingsImpl settings, + Map configurationValues, + Map cfg) { this.sessionFactory = (SessionFactoryImpl) sessionFactory; this.transactionType = settings.getTransactionType(); this.discardOnClose = settings.isReleaseResourcesOnCloseEnabled(); @@ -131,7 +141,7 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory { HashMap props = new HashMap(); addAll( props, sessionFactory.getProperties() ); - addAll( props, cfg.getProperties() ); + addAll( props, cfg ); addAll( props, configurationValues ); maskOutSensitiveInformation( props ); this.properties = Collections.unmodifiableMap( props ); diff --git a/hibernate-entitymanager/src/test/bundles/defaultpar/META-INF/persistence.xml b/hibernate-entitymanager/src/test/bundles/defaultpar/META-INF/persistence.xml index a2ae78019d..09d729711a 100644 --- a/hibernate-entitymanager/src/test/bundles/defaultpar/META-INF/persistence.xml +++ b/hibernate-entitymanager/src/test/bundles/defaultpar/META-INF/persistence.xml @@ -8,11 +8,11 @@ org.hibernate.jpa.test.pack.defaultpar.Lighter CALLBACK - - - - - + + + + + diff --git a/hibernate-entitymanager/src/test/bundles/defaultpar_1_0/META-INF/persistence.xml b/hibernate-entitymanager/src/test/bundles/defaultpar_1_0/META-INF/persistence.xml index 6984990e87..584b20fb7f 100644 --- a/hibernate-entitymanager/src/test/bundles/defaultpar_1_0/META-INF/persistence.xml +++ b/hibernate-entitymanager/src/test/bundles/defaultpar_1_0/META-INF/persistence.xml @@ -7,11 +7,11 @@ org.hibernate.jpa.test.pack.defaultpar.Lighter - - - - - + + + + + diff --git a/hibernate-entitymanager/src/test/bundles/excludehbmpar/META-INF/persistence.xml b/hibernate-entitymanager/src/test/bundles/excludehbmpar/META-INF/persistence.xml index 8b77ab369d..8d375b09c9 100644 --- a/hibernate-entitymanager/src/test/bundles/excludehbmpar/META-INF/persistence.xml +++ b/hibernate-entitymanager/src/test/bundles/excludehbmpar/META-INF/persistence.xml @@ -7,11 +7,11 @@ META-INF/orm2.xml - - - - - + + + + + diff --git a/hibernate-entitymanager/src/test/bundles/explicitpar/META-INF/persistence.xml b/hibernate-entitymanager/src/test/bundles/explicitpar/META-INF/persistence.xml index b2f0eefd40..95c0ce99df 100644 --- a/hibernate-entitymanager/src/test/bundles/explicitpar/META-INF/persistence.xml +++ b/hibernate-entitymanager/src/test/bundles/explicitpar/META-INF/persistence.xml @@ -14,11 +14,11 @@ - - - - - + + + + + diff --git a/hibernate-entitymanager/src/test/bundles/explodedpar/META-INF/persistence.xml b/hibernate-entitymanager/src/test/bundles/explodedpar/META-INF/persistence.xml index 1c40c44874..ee75b0a956 100644 --- a/hibernate-entitymanager/src/test/bundles/explodedpar/META-INF/persistence.xml +++ b/hibernate-entitymanager/src/test/bundles/explodedpar/META-INF/persistence.xml @@ -6,11 +6,11 @@ version="2.0"> - - - - - + + + + + diff --git a/hibernate-entitymanager/src/test/bundles/overridenpar/META-INF/persistence.xml b/hibernate-entitymanager/src/test/bundles/overridenpar/META-INF/persistence.xml index 84f4d72bac..d844da3db6 100644 --- a/hibernate-entitymanager/src/test/bundles/overridenpar/META-INF/persistence.xml +++ b/hibernate-entitymanager/src/test/bundles/overridenpar/META-INF/persistence.xml @@ -6,7 +6,6 @@ java:/unreachableDS - diff --git a/hibernate-entitymanager/src/test/bundles/overridenpar/overridenpar.properties b/hibernate-entitymanager/src/test/bundles/overridenpar/overridenpar.properties index 79b6559cef..b853586264 100644 --- a/hibernate-entitymanager/src/test/bundles/overridenpar/overridenpar.properties +++ b/hibernate-entitymanager/src/test/bundles/overridenpar/overridenpar.properties @@ -1,4 +1,6 @@ -hibernate.connection.driver_class @jdbc.driver@ -hibernate.connection.url @jdbc.url@ -hibernate.connection.username @jdbc.user@ -hibernate.connection.password @jdbc.pass@ \ No newline at end of file +hibernate.connection.driver_class org.h2.Driver +hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE +hibernate.connection.username sa +hibernate.connection.password + + diff --git a/hibernate-entitymanager/src/test/bundles/space par/META-INF/persistence.xml b/hibernate-entitymanager/src/test/bundles/space par/META-INF/persistence.xml index f7ffd56cc5..d60aaf08c6 100644 --- a/hibernate-entitymanager/src/test/bundles/space par/META-INF/persistence.xml +++ b/hibernate-entitymanager/src/test/bundles/space par/META-INF/persistence.xml @@ -6,11 +6,11 @@ version="2.0"> - - - - - + + + + + diff --git a/hibernate-entitymanager/src/test/bundles/war/WEB-INF/classes/META-INF/persistence.xml b/hibernate-entitymanager/src/test/bundles/war/WEB-INF/classes/META-INF/persistence.xml index 1180b46cdc..aecb4dc6d2 100644 --- a/hibernate-entitymanager/src/test/bundles/war/WEB-INF/classes/META-INF/persistence.xml +++ b/hibernate-entitymanager/src/test/bundles/war/WEB-INF/classes/META-INF/persistence.xml @@ -7,11 +7,11 @@ org.hibernate.jpa.test.pack.defaultpar.Lighter - - - - - + + + + + diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/BaseEntityManagerFunctionalTestCase.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/BaseEntityManagerFunctionalTestCase.java index 1e971c640e..0f0339ac46 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/BaseEntityManagerFunctionalTestCase.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/BaseEntityManagerFunctionalTestCase.java @@ -31,6 +31,7 @@ import javax.persistence.spi.PersistenceUnitTransactionType; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -40,7 +41,9 @@ import org.jboss.logging.Logger; import org.hibernate.cfg.Environment; import org.hibernate.dialect.Dialect; +import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.jpa.AvailableSettings; +import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl; import org.hibernate.jpa.internal.EntityManagerFactoryImpl; import org.hibernate.internal.util.StringHelper; import org.hibernate.jpa.HibernatePersistenceProvider; @@ -51,6 +54,7 @@ import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; import org.junit.After; import org.junit.Before; +import org.hibernate.testing.junit4.BaseFunctionalTestCase; import org.hibernate.testing.junit4.BaseUnitTestCase; /** @@ -59,23 +63,18 @@ import org.hibernate.testing.junit4.BaseUnitTestCase; * @author Emmanuel Bernard * @author Hardy Ferentschik */ -public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCase { +public abstract class BaseEntityManagerFunctionalTestCase extends BaseFunctionalTestCase { private static final Logger log = Logger.getLogger( BaseEntityManagerFunctionalTestCase.class ); // IMPL NOTE : Here we use @Before and @After (instead of @BeforeClassOnce and @AfterClassOnce like we do in // BaseCoreFunctionalTestCase) because the old HEM test methodology was to create an EMF for each test method. - private static final Dialect dialect = Dialect.getDialect(); private StandardServiceRegistryImpl serviceRegistry; private EntityManagerFactoryImpl entityManagerFactory; - private EntityManager em; private ArrayList isolatedEms = new ArrayList(); - protected Dialect getDialect() { - return dialect; - } protected EntityManagerFactory entityManagerFactory() { return entityManagerFactory; @@ -86,19 +85,19 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa } @Before - @SuppressWarnings( {"UnusedDeclaration"}) + @SuppressWarnings({ "UnusedDeclaration" }) public void buildEntityManagerFactory() throws Exception { log.trace( "Building EntityManagerFactory" ); - - entityManagerFactory = (EntityManagerFactoryImpl) Bootstrap.getEntityManagerFactoryBuilder( + EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder( buildPersistenceUnitDescriptor(), buildSettings() - ).build(); + ); + entityManagerFactory = (EntityManagerFactoryImpl) entityManagerFactoryBuilder.build(); serviceRegistry = (StandardServiceRegistryImpl) entityManagerFactory.getSessionFactory() .getServiceRegistry() .getParentServiceRegistry(); - + configuration = entityManagerFactoryBuilder.getHibernateConfiguration(); afterEntityManagerFactoryBuilt(); } @@ -195,7 +194,9 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa @SuppressWarnings("unchecked") protected Map buildSettings() { - Map settings = getConfig(); + + Map settings = Environment.getProperties(); + addConfigOptions( settings ); addMappings( settings ); if ( createSchema() ) { @@ -209,67 +210,53 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa @SuppressWarnings("unchecked") protected void addMappings(Map settings) { String[] mappings = getMappings(); - if ( mappings != null ) { + if ( mappings != null && mappings.length > 0 ) { settings.put( AvailableSettings.HBXML_FILES, StringHelper.join( ",", mappings ) ); } - } - - protected static final String[] NO_MAPPINGS = new String[0]; - - protected String[] getMappings() { - return NO_MAPPINGS; - } - - protected Map getConfig() { - Map config = Environment.getProperties(); - ArrayList classes = new ArrayList(); - - classes.addAll( Arrays.asList( getAnnotatedClasses() ) ); - config.put( AvailableSettings.LOADED_CLASSES, classes ); - for ( Map.Entry entry : getCachedClasses().entrySet() ) { - config.put( AvailableSettings.CLASS_CACHE_PREFIX + "." + entry.getKey().getName(), entry.getValue() ); - } - for ( Map.Entry entry : getCachedCollections().entrySet() ) { - config.put( AvailableSettings.COLLECTION_CACHE_PREFIX + "." + entry.getKey(), entry.getValue() ); - } - if ( getEjb3DD().length > 0 ) { - ArrayList dds = new ArrayList(); - dds.addAll( Arrays.asList( getEjb3DD() ) ); - config.put( AvailableSettings.XML_FILE_NAMES, dds ); + Class[] annotatedClasses = getAnnotatedClasses(); + if ( annotatedClasses != null && annotatedClasses.length > 0 ) { + List> classes = Arrays.asList( annotatedClasses ); + settings.put( AvailableSettings.LOADED_CLASSES, classes ); } - addConfigOptions( config ); - return config; + Map cachedClasses = getCachedClasses(); + if ( CollectionHelper.isNotEmpty( cachedClasses ) ) { + for ( Map.Entry entry : cachedClasses.entrySet() ) { + settings.put( AvailableSettings.CLASS_CACHE_PREFIX + "." + entry.getKey().getName(), entry.getValue() ); + } + } + Map cachedCollections = getCachedCollections(); + if ( CollectionHelper.isNotEmpty( cachedCollections ) ) { + for ( Map.Entry entry : cachedCollections.entrySet() ) { + settings.put( AvailableSettings.COLLECTION_CACHE_PREFIX + "." + entry.getKey(), entry.getValue() ); + } + } + + String[] dds = getEjb3DD(); + if ( dds != null && dds.length > 0 ) { + List list = Arrays.asList( dds ); + settings.put( AvailableSettings.XML_FILE_NAMES, list ); + } } protected void addConfigOptions(Map options) { } - protected static final Class[] NO_CLASSES = new Class[0]; - - protected Class[] getAnnotatedClasses() { - return NO_CLASSES; - } - public Map getCachedClasses() { - return new HashMap(); + return Collections.emptyMap(); } public Map getCachedCollections() { - return new HashMap(); + return Collections.emptyMap(); } public String[] getEjb3DD() { - return new String[] { }; + return NO_MAPPINGS; } protected void afterEntityManagerFactoryBuilt() { } - protected boolean createSchema() { - return true; - } - @After @SuppressWarnings( {"UnusedDeclaration"}) diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/association/AssociationTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/association/AssociationTest.java index f4d041c62f..0bce6b2624 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/association/AssociationTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/association/AssociationTest.java @@ -5,10 +5,12 @@ import javax.persistence.EntityManager; import org.junit.Test; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; /** * @author Emmanuel Bernard */ +@FailureExpectedWithNewMetamodel public class AssociationTest extends BaseEntityManagerFunctionalTestCase { @Test public void testBidirOneToOne() throws Exception { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cacheable/annotation/ConfigurationTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cacheable/annotation/ConfigurationTest.java index fc421bd19f..24d7f268aa 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cacheable/annotation/ConfigurationTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cacheable/annotation/ConfigurationTest.java @@ -125,6 +125,7 @@ public class ConfigurationTest extends BaseUnitTestCase { private Configuration buildConfiguration(SharedCacheMode mode) { Map settings = new HashMap(); settings.put( AvailableSettings.SHARED_CACHE_MODE, mode ); + settings.put( org.hibernate.metamodel.MetadataSources.USE_NEW_METADATA_MAPPINGS, "false" ); settings.put( Environment.CACHE_REGION_FACTORY, CustomRegionFactory.class.getName() ); settings.put( AvailableSettings.LOADED_CLASSES, diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/callbacks/CallbacksTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/callbacks/CallbacksTest.java index f6926a136f..9b0f5dec74 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/callbacks/CallbacksTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/callbacks/CallbacksTest.java @@ -12,6 +12,7 @@ import org.hibernate.jpa.test.Cat; import org.hibernate.jpa.test.Kitten; import org.hibernate.testing.FailureExpected; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -23,6 +24,7 @@ import static org.junit.Assert.fail; * @author Emmanuel Bernard */ @SuppressWarnings("unchecked") +@FailureExpectedWithNewMetamodel public class CallbacksTest extends BaseEntityManagerFunctionalTestCase { @Test public void testCallbackMethod() throws Exception { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cascade/CascadeTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cascade/CascadeTest.java index cac652d542..135bd772b5 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cascade/CascadeTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cascade/CascadeTest.java @@ -29,10 +29,12 @@ import javax.persistence.EntityTransaction; import org.junit.Test; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; /** * @author Max Rydahl Andersen */ +@FailureExpectedWithNewMetamodel public class CascadeTest extends BaseEntityManagerFunctionalTestCase { @Test public void testCascade() throws Exception { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cascade/FetchTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cascade/FetchTest.java index a49c644281..e763b814db 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cascade/FetchTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cascade/FetchTest.java @@ -34,6 +34,7 @@ import org.junit.Test; import org.hibernate.Hibernate; import org.hibernate.ejb.HibernateEntityManager; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -41,6 +42,7 @@ import static org.junit.Assert.assertTrue; /** * @author Emmanuel Bernard */ +@FailureExpectedWithNewMetamodel public class FetchTest extends BaseEntityManagerFunctionalTestCase { @Test public void testCascadeAndFetchCollection() throws Exception { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cascade/multicircle/MultiCircleJpaCascadeTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cascade/multicircle/MultiCircleJpaCascadeTest.java index 4ec860f7bd..3fc77376a4 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cascade/multicircle/MultiCircleJpaCascadeTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cascade/multicircle/MultiCircleJpaCascadeTest.java @@ -34,6 +34,7 @@ import org.junit.Test; import org.hibernate.TransientPropertyValueException; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.testing.FailureExpected; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -175,6 +176,7 @@ public class MultiCircleJpaCascadeTest extends BaseEntityManagerFunctionalTestCa } @Test + @FailureExpectedWithNewMetamodel public void testPersist() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -186,6 +188,7 @@ public class MultiCircleJpaCascadeTest extends BaseEntityManagerFunctionalTestCa } @Test + @FailureExpectedWithNewMetamodel public void testPersistNoCascadeToTransient() { skipCleanup = true; EntityManager em = getOrCreateEntityManager(); @@ -326,7 +329,8 @@ public class MultiCircleJpaCascadeTest extends BaseEntityManagerFunctionalTestCa D.class, E.class, F.class, - G.class + G.class, + AbstractEntity.class }; } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cascade/multilevel/MultiLevelCascadeTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cascade/multilevel/MultiLevelCascadeTest.java index 61fc84c3f1..ebcc81d5f7 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cascade/multilevel/MultiLevelCascadeTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cascade/multilevel/MultiLevelCascadeTest.java @@ -29,12 +29,14 @@ import javax.persistence.EntityTransaction; import org.junit.Test; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; +@FailureExpectedWithNewMetamodel public class MultiLevelCascadeTest extends BaseEntityManagerFunctionalTestCase { @TestForIssue( jiraKey = "HHH-5299" ) diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cdi/BasicCDITest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cdi/BasicCDITest.java index a15615f668..8bacc34c5f 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cdi/BasicCDITest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cdi/BasicCDITest.java @@ -39,11 +39,14 @@ import java.util.List; import org.junit.Test; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; + import static org.junit.Assert.assertEquals; /** * @author Steve Ebersole */ +@FailureExpectedWithNewMetamodel public class BasicCDITest extends BaseCDIIntegrationTest { private static int count; diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/collection/PostLoadTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/collection/PostLoadTest.java index da059f3059..cbba2b5bc9 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/collection/PostLoadTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/collection/PostLoadTest.java @@ -8,10 +8,12 @@ import java.util.Set; import javax.persistence.EntityManager; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; import org.junit.Test; @TestForIssue( jiraKey="HHH-6043" ) +@FailureExpectedWithNewMetamodel public class PostLoadTest extends BaseEntityManagerFunctionalTestCase { /** diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/CriteriaCompilingTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/CriteriaCompilingTest.java index 1dfddc7fa7..a751625195 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/CriteriaCompilingTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/CriteriaCompilingTest.java @@ -40,6 +40,7 @@ import org.junit.Assert; import org.junit.Test; import org.hibernate.dialect.DB2Dialect; +import org.hibernate.jpa.test.callbacks.CommunicationSystem; import org.hibernate.jpa.test.metamodel.Address; import org.hibernate.jpa.test.metamodel.Alias; import org.hibernate.jpa.test.metamodel.Country; @@ -60,11 +61,13 @@ import org.hibernate.jpa.test.inheritance.Fruit; import org.hibernate.jpa.test.inheritance.Strawberry; import org.hibernate.testing.FailureExpected; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.RequiresDialect; /** * @author Steve Ebersole */ +@FailureExpectedWithNewMetamodel public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase { @Override public Class[] getAnnotatedClasses() { @@ -81,6 +84,7 @@ public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase { Order.class, Product.class, ShelfLife.class, + CommunicationSystem.class, // @Inheritance Fruit.class, Strawberry.class, diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/ManipulationCriteriaTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/ManipulationCriteriaTest.java index 07690367dc..ba8afadf9d 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/ManipulationCriteriaTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/ManipulationCriteriaTest.java @@ -37,12 +37,14 @@ import org.hibernate.dialect.MySQLDialect; import org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest; import org.hibernate.jpa.test.metamodel.Customer; import org.hibernate.jpa.test.metamodel.Customer_; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.SkipForDialect; import org.junit.Test; /** * @author Steve Ebersole */ +@FailureExpectedWithNewMetamodel public class ManipulationCriteriaTest extends AbstractMetamodelSpecificTest { @Test public void basicTest() { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/OnKeywordTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/OnKeywordTest.java index ae79bda3bf..3e88386619 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/OnKeywordTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/OnKeywordTest.java @@ -33,6 +33,7 @@ import org.hibernate.jpa.test.metamodel.LineItem; import org.hibernate.jpa.test.metamodel.LineItem_; import org.hibernate.jpa.test.metamodel.Order; import org.hibernate.jpa.test.metamodel.Order_; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; @@ -41,6 +42,7 @@ import org.junit.Test; * * @author Steve Ebersole */ +@FailureExpectedWithNewMetamodel public class OnKeywordTest extends AbstractMetamodelSpecificTest { @Test public void basicTest() { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/ParameterTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/ParameterTest.java index d7eff0a474..9a21a77228 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/ParameterTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/ParameterTest.java @@ -33,10 +33,12 @@ import javax.persistence.criteria.Root; import org.junit.Test; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; /** * @author Steve Ebersole */ +@FailureExpectedWithNewMetamodel public class ParameterTest extends BaseEntityManagerFunctionalTestCase { @Test diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/QueryBuilderTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/QueryBuilderTest.java index 25b0972907..2ea444d58b 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/QueryBuilderTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/QueryBuilderTest.java @@ -51,12 +51,14 @@ import org.hibernate.jpa.test.metamodel.Product; import org.hibernate.jpa.test.metamodel.ShelfLife; import org.hibernate.jpa.test.metamodel.Spouse; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import static org.junit.Assert.assertEquals; /** * @author Steve Ebersole */ +@FailureExpectedWithNewMetamodel public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { @Override public Class[] getAnnotatedClasses() { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/TreatKeywordTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/TreatKeywordTest.java index b1033b5c16..5067524199 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/TreatKeywordTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/TreatKeywordTest.java @@ -36,6 +36,7 @@ import org.hibernate.jpa.test.metamodel.Thing; import org.hibernate.jpa.test.metamodel.ThingWithQuantity; import org.hibernate.jpa.test.metamodel.ThingWithQuantity_; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; @@ -50,6 +51,7 @@ public class TreatKeywordTest extends BaseEntityManagerFunctionalTestCase { } @Test + @FailureExpectedWithNewMetamodel public void basicTest() { EntityManager em = getOrCreateEntityManager(); CriteriaBuilder builder = em.getCriteriaBuilder(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/AggregationResultTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/AggregationResultTest.java index 11348c8865..24099ad1df 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/AggregationResultTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/AggregationResultTest.java @@ -38,10 +38,12 @@ import org.junit.Test; import org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest; import org.hibernate.jpa.test.metamodel.Product; import org.hibernate.jpa.test.metamodel.Product_; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; /** * @author Steve Ebersole */ +@FailureExpectedWithNewMetamodel public class AggregationResultTest extends AbstractMetamodelSpecificTest { private CriteriaBuilder builder; diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/CastTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/CastTest.java index 72c159d2f6..07819acc1a 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/CastTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/CastTest.java @@ -38,8 +38,10 @@ import org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest; import org.hibernate.jpa.test.metamodel.Product; import org.hibernate.jpa.test.metamodel.Product_; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; +@FailureExpectedWithNewMetamodel public class CastTest extends AbstractMetamodelSpecificTest { private static final int QUANTITY = 2; diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/ExpressionsTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/ExpressionsTest.java index 81632e2661..bd155d336f 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/ExpressionsTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/ExpressionsTest.java @@ -46,6 +46,7 @@ import org.hibernate.jpa.test.metamodel.Phone; import org.hibernate.jpa.test.metamodel.Product; import org.hibernate.jpa.test.metamodel.Product_; import org.hibernate.internal.AbstractQueryImpl; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; @@ -56,6 +57,7 @@ import static org.junit.Assert.assertEquals; * * @author Steve Ebersole */ +@FailureExpectedWithNewMetamodel public class ExpressionsTest extends AbstractMetamodelSpecificTest { private CriteriaBuilder builder; diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/PredicateTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/PredicateTest.java index 8e8f6a36af..eda7071bd1 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/PredicateTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/PredicateTest.java @@ -39,6 +39,7 @@ import org.hibernate.jpa.test.metamodel.Customer_; import org.hibernate.jpa.test.metamodel.Order; import org.hibernate.jpa.test.metamodel.Order_; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; import static org.junit.Assert.assertEquals; @@ -50,6 +51,7 @@ import static org.junit.Assert.assertTrue; * @author Steve Ebersole * @author Hardy Ferentschik */ +@FailureExpectedWithNewMetamodel public class PredicateTest extends AbstractMetamodelSpecificTest { private CriteriaBuilder builder; diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/components/ComponentCriteriaTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/components/ComponentCriteriaTest.java index 791ce87ad7..1fdb1bc1ea 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/components/ComponentCriteriaTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/components/ComponentCriteriaTest.java @@ -35,6 +35,7 @@ import org.junit.Test; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; /** @@ -43,7 +44,7 @@ import org.hibernate.testing.TestForIssue; public class ComponentCriteriaTest extends BaseEntityManagerFunctionalTestCase { @Override public Class[] getAnnotatedClasses() { - return new Class[] { Client.class }; + return new Class[] { Client.class, Name.class }; } @Test @@ -86,6 +87,7 @@ public class ComponentCriteriaTest extends BaseEntityManagerFunctionalTestCase { @Test @TestForIssue( jiraKey = "HHH-4586" ) + @FailureExpectedWithNewMetamodel public void testParameterizedFunctions() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/idclass/IdClassPredicateTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/idclass/IdClassPredicateTest.java index 5316db25b7..47356b9811 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/idclass/IdClassPredicateTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/idclass/IdClassPredicateTest.java @@ -47,7 +47,9 @@ public class IdClassPredicateTest extends AbstractMetamodelSpecificTest { public Class[] getAnnotatedClasses() { return new Class[] { Widget.class, - Tool.class + Tool.class, + Helper.class, + HelperId.class }; } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/paths/AbstractPathImplTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/paths/AbstractPathImplTest.java index fef848f7e2..84fbaf1728 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/paths/AbstractPathImplTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/paths/AbstractPathImplTest.java @@ -36,6 +36,7 @@ import org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest; import org.hibernate.jpa.test.metamodel.Order; import org.hibernate.jpa.test.metamodel.Thing; import org.hibernate.jpa.test.metamodel.ThingWithQuantity; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import static org.junit.Assert.assertEquals; @@ -43,6 +44,7 @@ import static org.junit.Assert.assertEquals; * @author Michael Rudolf * @author James Gilbertson */ +@FailureExpectedWithNewMetamodel public class AbstractPathImplTest extends AbstractMetamodelSpecificTest { @Before public void prepareTestData() { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/paths/ImplicitJoinTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/paths/ImplicitJoinTest.java index c3185ba801..3031c9bb59 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/paths/ImplicitJoinTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/paths/ImplicitJoinTest.java @@ -37,10 +37,12 @@ import org.hibernate.jpa.test.metamodel.LineItem; import org.hibernate.jpa.test.metamodel.LineItem_; import org.hibernate.jpa.test.metamodel.Order; import org.hibernate.jpa.test.metamodel.Order_; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; /** * @author Steve Ebersole */ +@FailureExpectedWithNewMetamodel public class ImplicitJoinTest extends AbstractMetamodelSpecificTest { @Test public void testImplicitJoinFromExplicitCollectionJoin() { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/subquery/CorrelatedSubqueryTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/subquery/CorrelatedSubqueryTest.java index 4f7364f9ec..8b538f3359 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/subquery/CorrelatedSubqueryTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/subquery/CorrelatedSubqueryTest.java @@ -40,11 +40,13 @@ import org.hibernate.jpa.test.metamodel.LineItem; import org.hibernate.jpa.test.metamodel.LineItem_; import org.hibernate.jpa.test.metamodel.Order; import org.hibernate.jpa.test.metamodel.Order_; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.SkipForDialect; /** * @author Steve Ebersole */ +@FailureExpectedWithNewMetamodel public class CorrelatedSubqueryTest extends AbstractMetamodelSpecificTest { @Test public void testBasicCorrelation() { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/subquery/UncorrelatedSubqueryTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/subquery/UncorrelatedSubqueryTest.java index c3282b5e38..5902ec710a 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/subquery/UncorrelatedSubqueryTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/subquery/UncorrelatedSubqueryTest.java @@ -35,6 +35,7 @@ import org.hibernate.jpa.test.metamodel.Customer; import org.hibernate.jpa.test.metamodel.Customer_; import org.hibernate.jpa.test.metamodel.Order; import org.hibernate.jpa.test.metamodel.Order_; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; @@ -43,6 +44,7 @@ import static org.junit.Assert.fail; /** * @author Steve Ebersole */ +@FailureExpectedWithNewMetamodel public class UncorrelatedSubqueryTest extends AbstractMetamodelSpecificTest { @Test public void testEqualAll() { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/tuple/TupleCriteriaTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/tuple/TupleCriteriaTest.java index c0ea0eb5f9..086776fda2 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/tuple/TupleCriteriaTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/tuple/TupleCriteriaTest.java @@ -36,6 +36,7 @@ import org.junit.Test; import org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest; import org.hibernate.jpa.test.metamodel.Customer; import org.hibernate.jpa.test.metamodel.Customer_; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -43,6 +44,7 @@ import static org.junit.Assert.assertTrue; /** * @author Emmanuel Bernard */ +@FailureExpectedWithNewMetamodel public class TupleCriteriaTest extends AbstractMetamodelSpecificTest { @Test public void testArray() { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/EntityManagerFactorySerializationTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/EntityManagerFactorySerializationTest.java index 8e268b3757..4d2461af91 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/EntityManagerFactorySerializationTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/EntityManagerFactorySerializationTest.java @@ -41,7 +41,9 @@ import org.hibernate.jpa.test.Cat; import org.hibernate.jpa.test.Distributor; import org.hibernate.jpa.test.Item; import org.hibernate.jpa.test.Kitten; +import org.hibernate.jpa.test.LastUpdateListener; import org.hibernate.jpa.test.Wallet; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -49,6 +51,7 @@ import static org.junit.Assert.assertTrue; /** * @author Emmanuel Bernard */ +@FailureExpectedWithNewMetamodel public class EntityManagerFactorySerializationTest extends BaseEntityManagerFunctionalTestCase { @Test public void testSerialization() throws Exception { @@ -145,7 +148,8 @@ public class EntityManagerFactorySerializationTest extends BaseEntityManagerFunc Distributor.class, Wallet.class, Cat.class, - Kitten.class + Kitten.class, + LastUpdateListener.class }; } } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/EntityManagerSerializationTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/EntityManagerSerializationTest.java index 4b0c8f4273..235efd25d7 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/EntityManagerSerializationTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/EntityManagerSerializationTest.java @@ -42,11 +42,13 @@ import org.hibernate.jpa.test.Item; import org.hibernate.jpa.test.Kitten; import org.hibernate.jpa.test.NotSerializableClass; import org.hibernate.jpa.test.Wallet; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; /** * @author Emmanuel Bernard * @author Scott Marlow */ +@FailureExpectedWithNewMetamodel public class EntityManagerSerializationTest extends BaseEntityManagerFunctionalTestCase { @Test public void testSerialization() throws Exception { @@ -102,10 +104,8 @@ public class EntityManagerSerializationTest extends BaseEntityManagerFunctionalT * @return */ @Override - protected Map getConfig() { - Map result = super.getConfig(); - result.put( "BaseEntityManagerFunctionalTestCase.getConfig_addedNotSerializableObject", new NotSerializableClass()); - return result; + protected void addConfigOptions(Map options) { + options.put( "BaseEntityManagerFunctionalTestCase.getConfig_addedNotSerializableObject", new NotSerializableClass()); } @Override diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/PersisterClassProviderTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/PersisterClassProviderTest.java index 996175acfc..5c0016f2f8 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/PersisterClassProviderTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/PersisterClassProviderTest.java @@ -54,6 +54,7 @@ import org.hibernate.jpa.boot.spi.Bootstrap; import org.hibernate.mapping.Collection; import org.hibernate.mapping.PersistentClass; import org.hibernate.metadata.ClassMetadata; +import org.hibernate.metamodel.MetadataSources; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; import org.hibernate.persister.collection.CollectionPersister; @@ -113,10 +114,10 @@ public class PersisterClassProviderTest { return null; } } - + @SuppressWarnings( {"UnusedParameters"}) public static class GoofyProvider implements EntityPersister { - @SuppressWarnings( {"UnusedParameters"}) + public GoofyProvider( org.hibernate.mapping.PersistentClass persistentClass, org.hibernate.cache.spi.access.EntityRegionAccessStrategy strategy, @@ -126,6 +127,15 @@ public class PersisterClassProviderTest { throw new GoofyException(); } + public GoofyProvider( + EntityBinding persistentClass, + org.hibernate.cache.spi.access.EntityRegionAccessStrategy strategy, + NaturalIdRegionAccessStrategy naturalIdRegionAccessStrategy, + SessionFactoryImplementor sf, + Mapping mapping) { + throw new GoofyException(); + } + @Override public EntityMode getEntityMode() { return null; diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/emops/MergeTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/emops/MergeTest.java index d424cf4b4d..e319ee40dc 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/emops/MergeTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/emops/MergeTest.java @@ -30,6 +30,7 @@ import javax.persistence.EntityManager; import org.junit.Test; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -37,6 +38,7 @@ import static org.junit.Assert.fail; /** * @author Emmanuel Bernard */ +@FailureExpectedWithNewMetamodel public class MergeTest extends BaseEntityManagerFunctionalTestCase { @Test public void testMergeWithIndexColumn() { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/exception/ExceptionTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/exception/ExceptionTest.java index 01d495604d..e15ac2d9db 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/exception/ExceptionTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/exception/ExceptionTest.java @@ -36,6 +36,7 @@ import org.hibernate.cfg.Environment; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.exception.ConstraintViolationException; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; import static org.junit.Assert.assertEquals; @@ -46,6 +47,7 @@ import static org.junit.Assert.fail; * @author Emmanuel Bernard */ @SuppressWarnings("unchecked") +@FailureExpectedWithNewMetamodel public class ExceptionTest extends BaseEntityManagerFunctionalTestCase { private static final Logger log = Logger.getLogger( ExceptionTest.class ); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/graphs/BasicEntityGraphTests.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/graphs/BasicEntityGraphTests.java index 0f9fd767c6..25881f3c09 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/graphs/BasicEntityGraphTests.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/graphs/BasicEntityGraphTests.java @@ -35,6 +35,7 @@ import javax.persistence.Subgraph; import java.util.Set; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; @@ -61,6 +62,7 @@ public class BasicEntityGraphTests extends BaseEntityManagerFunctionalTestCase { } @Test + @FailureExpectedWithNewMetamodel public void testBasicSubgraphBuilding() { EntityManager em = getOrCreateEntityManager(); EntityGraph graphRoot = em.createEntityGraph( Entity1.class ); @@ -80,6 +82,7 @@ public class BasicEntityGraphTests extends BaseEntityManagerFunctionalTestCase { } @Test + @FailureExpectedWithNewMetamodel public void testBasicGraphImmutability() { EntityManager em = getOrCreateEntityManager(); EntityGraph graphRoot = em.createEntityGraph( Entity1.class ); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/jee/OrmVersionTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/jee/OrmVersionTest.java index 12ef149465..12290d02fd 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/jee/OrmVersionTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/jee/OrmVersionTest.java @@ -42,19 +42,27 @@ import org.junit.Test; import org.hibernate.InvalidMappingException; import org.hibernate.jpa.HibernatePersistenceProvider; +import org.hibernate.jpa.test.pack.defaultpar.ApplicationServer; import org.hibernate.jpa.test.pack.defaultpar.Lighter; +import org.hibernate.jpa.test.pack.defaultpar_1_0.ApplicationServer1; +import org.hibernate.jpa.test.pack.defaultpar_1_0.IncrementListener1; import org.hibernate.jpa.test.pack.defaultpar_1_0.Lighter1; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; +import org.hibernate.testing.junit4.BaseUnitTestCase; /** * "smoke" tests for JEE bootstrapping of HEM via a {@link PersistenceUnitInfo} * * @author Steve Ebersole */ -public class OrmVersionTest { +@FailureExpectedWithNewMetamodel +public class OrmVersionTest extends BaseUnitTestCase{ @Test public void testOrm1() { PersistenceUnitInfoImpl pui = new PersistenceUnitInfoImpl( "orm1-test", "1.0" ) .addMappingFileName( "org/hibernate/jpa/test/jee/valid-orm-1.xml" ); + pui.getManagedClassNames().add( IncrementListener1.class.getName() ); + pui.getManagedClassNames().add( ApplicationServer1.class.getName() ); HibernatePersistenceProvider hp = new HibernatePersistenceProvider(); EntityManagerFactory emf = hp.createContainerEntityManagerFactory( pui, Collections.EMPTY_MAP ); emf.getMetamodel().entity( Lighter1.class ); // exception if not entity @@ -63,6 +71,8 @@ public class OrmVersionTest { public void testOrm2() { PersistenceUnitInfoImpl pui = new PersistenceUnitInfoImpl( "orm2-test", "2.0" ) .addMappingFileName( "org/hibernate/jpa/test/jee/valid-orm-2.xml" ); + pui.getManagedClassNames().add( org.hibernate.jpa.test.pack.defaultpar.IncrementListener.class.getName() ); + pui.getManagedClassNames().add( ApplicationServer.class.getName() ); HibernatePersistenceProvider hp = new HibernatePersistenceProvider(); EntityManagerFactory emf = hp.createContainerEntityManagerFactory( pui, Collections.EMPTY_MAP ); emf.getMetamodel().entity( Lighter.class ); // exception if not entity @@ -71,6 +81,8 @@ public class OrmVersionTest { public void testInvalidOrm1() { PersistenceUnitInfoImpl pui = new PersistenceUnitInfoImpl( "invalid-orm1-test", "1.0" ) .addMappingFileName( "org/hibernate/jpa/test/jee/invalid-orm-1.xml" ); + pui.getManagedClassNames().add( IncrementListener1.class.getName() ); + pui.getManagedClassNames().add( ApplicationServer1.class.getName() ); HibernatePersistenceProvider hp = new HibernatePersistenceProvider(); try { hp.createContainerEntityManagerFactory( pui, Collections.EMPTY_MAP ); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java index b98b6e07d8..6f23426606 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java @@ -44,6 +44,7 @@ import org.hibernate.cfg.Configuration; import org.hibernate.jpa.metamodel.internal.legacy.MetamodelImpl; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -56,6 +57,7 @@ import static org.junit.Assert.fail; /** * @author Emmanuel Bernard */ +@FailureExpectedWithNewMetamodel public class MetadataTest extends BaseEntityManagerFunctionalTestCase { @Test public void testBaseOfService() throws Exception { @@ -408,12 +410,15 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase { Dog.class, Cat.class, Cattish.class, + Animal.class, Feline.class, Garden.class, Flower.class, JoinedManyToOneOwner.class, Parent.class, - Child.class + Child.class, + SubThing.class, + Thing.class }; } 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 791e34fc3a..3c2e5f1cb0 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,12 +28,14 @@ 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-entitymanager/src/test/java/org/hibernate/jpa/test/metadata/StaticMetadataTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metadata/StaticMetadataTest.java index bc42608339..f19a290ccd 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metadata/StaticMetadataTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metadata/StaticMetadataTest.java @@ -33,6 +33,7 @@ import javax.persistence.metamodel.Type; import org.junit.Test; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -42,6 +43,7 @@ import static org.junit.Assert.assertTrue; /** * @author Steve Ebersole */ +@FailureExpectedWithNewMetamodel public class StaticMetadataTest extends BaseEntityManagerFunctionalTestCase { @Test public void testInjections() throws Exception { @@ -143,7 +145,11 @@ public class StaticMetadataTest extends BaseEntityManagerFunctionalTestCase { Cattish.class, Feline.class, Garden.class, - Flower.class + Flower.class, + Animal.class, + SubThing.class, + Thing.class , + Cattish.class }; } } \ No newline at end of file diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/attribute/MappedSuperclassWithAttributesTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/attribute/MappedSuperclassWithAttributesTest.java index d10aea0686..8c811fe5ac 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/attribute/MappedSuperclassWithAttributesTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/attribute/MappedSuperclassWithAttributesTest.java @@ -33,6 +33,7 @@ import org.hibernate.jpa.AvailableSettings; import org.junit.Test; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; @@ -42,12 +43,13 @@ import static org.junit.Assert.assertNotNull; * @author Steve Ebersole */ @TestForIssue( jiraKey = "HHH-5024" ) +@FailureExpectedWithNewMetamodel(message = "jpa metamodel generation") public class MappedSuperclassWithAttributesTest extends BaseUnitTestCase { @Test public void testStaticMetamodel() { EntityManagerFactory emf = TestingEntityManagerFactoryGenerator.generateEntityManagerFactory( AvailableSettings.LOADED_CLASSES, - Arrays.asList( Product.class ) + Arrays.asList( Product.class,AbstractNameable.class ) ); assertNotNull( "'Product_.id' should not be null)", Product_.id ); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embedded/MappedSuperclassWithEmbeddedTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embedded/MappedSuperclassWithEmbeddedTest.java index 1cd2b2bbbe..8fcd2ce618 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embedded/MappedSuperclassWithEmbeddedTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embedded/MappedSuperclassWithEmbeddedTest.java @@ -31,6 +31,7 @@ import org.hibernate.jpa.AvailableSettings; import org.junit.Test; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; @@ -39,13 +40,14 @@ import static org.junit.Assert.assertNotNull; /** * @author Steve Ebersole */ +@FailureExpectedWithNewMetamodel(message = "jpa metamodel generation") public class MappedSuperclassWithEmbeddedTest extends BaseUnitTestCase { @Test @TestForIssue( jiraKey = "HHH-5024" ) public void testStaticMetamodel() { EntityManagerFactory emf = TestingEntityManagerFactoryGenerator.generateEntityManagerFactory( AvailableSettings.LOADED_CLASSES, - Arrays.asList( Company.class ) + Arrays.asList( Company.class, AbstractAddressable.class, Address.class ) ); assertNotNull( "'Company_.id' should not be null)", Company_.id ); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embeddedid/MappedSuperclassWithEmbeddedIdTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embeddedid/MappedSuperclassWithEmbeddedIdTest.java index 399b25ed14..7e02366243 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embeddedid/MappedSuperclassWithEmbeddedIdTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embeddedid/MappedSuperclassWithEmbeddedIdTest.java @@ -31,6 +31,7 @@ import org.hibernate.jpa.AvailableSettings; import org.junit.Test; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; @@ -39,13 +40,14 @@ import static org.junit.Assert.assertNotNull; /** * @author Steve Ebersole */ +@FailureExpectedWithNewMetamodel public class MappedSuperclassWithEmbeddedIdTest extends BaseUnitTestCase { @Test @TestForIssue( jiraKey = "HHH-5024" ) public void testStaticMetamodel() { EntityManagerFactory emf = TestingEntityManagerFactoryGenerator.generateEntityManagerFactory( AvailableSettings.LOADED_CLASSES, - Arrays.asList( Product.class ) + Arrays.asList( Product.class, AbstractProduct.class, ProductId.class ) ); assertNotNull( "'Product_.description' should not be null)", Product_.description ); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/idclass/MappedSuperclassWithEntityWithIdClassTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/idclass/MappedSuperclassWithEntityWithIdClassTest.java index 47bffab5e9..4905351061 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/idclass/MappedSuperclassWithEntityWithIdClassTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/idclass/MappedSuperclassWithEntityWithIdClassTest.java @@ -31,6 +31,7 @@ import org.hibernate.jpa.AvailableSettings; import org.junit.Test; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; @@ -40,13 +41,14 @@ import static org.junit.Assert.assertNotNull; * @author Alexis Bataille * @author Steve Ebersole */ +@FailureExpectedWithNewMetamodel public class MappedSuperclassWithEntityWithIdClassTest extends BaseUnitTestCase { @Test @TestForIssue( jiraKey = "HHH-5024" ) public void testStaticMetamodel() { EntityManagerFactory emf = TestingEntityManagerFactoryGenerator.generateEntityManagerFactory( AvailableSettings.LOADED_CLASSES, - Arrays.asList( ProductAttribute.class ) + Arrays.asList( ProductAttribute.class, AbstractAttribute.class ) ); assertNotNull( "'ProductAttribute_.value' should not be null)", ProductAttribute_.value ); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metamodel/MappedSuperclassTypeTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metamodel/MappedSuperclassTypeTest.java index b9c0014317..1ab1400767 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metamodel/MappedSuperclassTypeTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metamodel/MappedSuperclassTypeTest.java @@ -29,6 +29,7 @@ import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.junit.Test; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; import static org.junit.Assert.assertNotNull; @@ -36,10 +37,11 @@ import static org.junit.Assert.assertNotNull; /** * @author Steve Ebersole */ +@FailureExpectedWithNewMetamodel public class MappedSuperclassTypeTest extends BaseEntityManagerFunctionalTestCase { @Override public Class[] getAnnotatedClasses() { - return new Class[] { SomeMappedSuperclassSubclass.class }; + return new Class[] { SomeMappedSuperclassSubclass.class, SomeMappedSuperclass.class }; } @Test diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/PackagedEntityManagerTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/PackagedEntityManagerTest.java index 2fed86b63a..6384c1d6ed 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/PackagedEntityManagerTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/PackagedEntityManagerTest.java @@ -61,6 +61,7 @@ import org.hibernate.event.service.spi.EventListenerRegistry; import org.hibernate.event.spi.EventType; import org.hibernate.internal.util.ConfigHelper; import org.hibernate.stat.Statistics; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -80,6 +81,7 @@ import static org.junit.Assert.fail; @SuppressWarnings("unchecked") public class PackagedEntityManagerTest extends PackagingTestCase { @Test + @FailureExpectedWithNewMetamodel public void testDefaultPar() throws Exception { File testPackage = buildDefaultPar(); addPackageToClasspath( testPackage ); @@ -115,6 +117,7 @@ public class PackagedEntityManagerTest extends PackagingTestCase { } @Test + @FailureExpectedWithNewMetamodel public void testDefaultParForPersistence_1_0() throws Exception { File testPackage = buildDefaultPar_1_0(); addPackageToClasspath( testPackage ); @@ -149,6 +152,7 @@ public class PackagedEntityManagerTest extends PackagingTestCase { } @Test + @FailureExpectedWithNewMetamodel public void testListenersDefaultPar() throws Exception { File testPackage = buildDefaultPar(); addPackageToClasspath( testPackage ); @@ -189,6 +193,7 @@ public class PackagedEntityManagerTest extends PackagingTestCase { } @Test + @FailureExpectedWithNewMetamodel public void testExplodedPar() throws Exception { File testPackage = buildExplodedPar(); addPackageToClasspath( testPackage ); @@ -248,6 +253,7 @@ public class PackagedEntityManagerTest extends PackagingTestCase { } @Test + @FailureExpectedWithNewMetamodel public void testCfgXmlPar() throws Exception { File testPackage = buildCfgXmlPar(); addPackageToClasspath( testPackage ); @@ -320,6 +326,7 @@ public class PackagedEntityManagerTest extends PackagingTestCase { } @Test + @FailureExpectedWithNewMetamodel public void testListeners() throws Exception { File testPackage = buildExplicitPar(); addPackageToClasspath( testPackage ); @@ -340,6 +347,7 @@ public class PackagedEntityManagerTest extends PackagingTestCase { } @Test + @FailureExpectedWithNewMetamodel public void testExtendedEntityManager() throws Exception { File testPackage = buildExplicitPar(); addPackageToClasspath( testPackage ); @@ -390,6 +398,7 @@ public class PackagedEntityManagerTest extends PackagingTestCase { } @Test + @FailureExpectedWithNewMetamodel public void testConfiguration() throws Exception { File testPackage = buildExplicitPar(); addPackageToClasspath( testPackage ); @@ -443,6 +452,7 @@ public class PackagedEntityManagerTest extends PackagingTestCase { } @Test + @FailureExpectedWithNewMetamodel public void testExternalJar() throws Exception { File externalJar = buildExternalJar(); File testPackage = buildExplicitPar(); @@ -468,6 +478,7 @@ public class PackagedEntityManagerTest extends PackagingTestCase { } @Test + @FailureExpectedWithNewMetamodel public void testORMFileOnMainAndExplicitJars() throws Exception { File testPackage = buildExplicitPar(); addPackageToClasspath( testPackage ); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/PackagingTestCase.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/PackagingTestCase.java index af86c8aeae..bb13430812 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/PackagingTestCase.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/PackagingTestCase.java @@ -93,6 +93,9 @@ public abstract class PackagingTestCase extends BaseCoreFunctionalTestCase { } else { // if running in some IDEs, may be in /bin instead index = myUrl.getFile().lastIndexOf( "bin" ); + if(index == -1){ + index = myUrl.getFile().lastIndexOf( "out" ); + } } if ( index == -1 ) { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/ScannerTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/ScannerTest.java index 28ed10ab8e..7bf4f2d8ea 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/ScannerTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/ScannerTest.java @@ -42,6 +42,7 @@ import org.hibernate.jpa.boot.scan.spi.ScanResult; import org.hibernate.jpa.boot.scan.spi.Scanner; import org.hibernate.jpa.test.pack.defaultpar.ApplicationServer; import org.hibernate.jpa.test.pack.defaultpar.Version; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; @@ -94,6 +95,7 @@ public class ScannerTest extends PackagingTestCase { } @Test + @FailureExpectedWithNewMetamodel public void testCustomScanner() throws Exception { File defaultPar = buildDefaultPar(); File explicitPar = buildExplicitPar(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/query/QueryTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/query/QueryTest.java index dea77ad3a0..94a9b6db5f 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/query/QueryTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/query/QueryTest.java @@ -40,6 +40,7 @@ import org.hibernate.jpa.test.Distributor; import org.hibernate.jpa.test.Item; import org.hibernate.jpa.test.Wallet; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; import static org.junit.Assert.assertEquals; @@ -308,6 +309,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { } @Test + @FailureExpectedWithNewMetamodel public void testNativeQueryByResultSet() { Item item = new Item( "Mouse", "Micro$oft mouse" ); @@ -581,6 +583,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { } @Test + @FailureExpectedWithNewMetamodel public void testTypedNamedNativeQuery() { Item item = new Item( "Mouse", "Micro$oft mouse" ); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/transaction/SynchronizationTypeTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/transaction/SynchronizationTypeTest.java index 05bb4d8e3a..335597645e 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/transaction/SynchronizationTypeTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/transaction/SynchronizationTypeTest.java @@ -41,6 +41,7 @@ import org.hibernate.jpa.AvailableSettings; import org.junit.Test; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.jta.TestingJtaBootstrap; import org.hibernate.testing.jta.TestingJtaPlatformImpl; @@ -119,6 +120,7 @@ public class SynchronizationTypeTest extends BaseEntityManagerFunctionalTestCase } @Test + @FailureExpectedWithNewMetamodel public void testDisallowedOperations() throws Exception { // test calling operations that are disallowed while a UNSYNCHRONIZED persistence context is not // yet joined/enlisted diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/util/GetIdentifierTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/util/GetIdentifierTest.java index b86979fbc3..ee63b43daa 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/util/GetIdentifierTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/util/GetIdentifierTest.java @@ -117,7 +117,9 @@ public class GetIdentifierTest extends BaseEntityManagerFunctionalTestCase { public Class[] getAnnotatedClasses() { return new Class[] { Book.class, + CopyrightableContent.class, Umbrella.class, + Umbrella.PK.class, Sickness.class, Author.class, Article.class diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/util/IsLoadedTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/util/IsLoadedTest.java index f63e965fe4..1b94cabcaf 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/util/IsLoadedTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/util/IsLoadedTest.java @@ -28,6 +28,7 @@ import javax.persistence.EntityManager; import org.junit.Test; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -37,6 +38,7 @@ import static org.junit.Assert.assertTrue; */ public class IsLoadedTest extends BaseEntityManagerFunctionalTestCase { @Test + @FailureExpectedWithNewMetamodel public void testIsLoadedOnPrivateSuperclassProperty() { EntityManager em = entityManagerFactory().createEntityManager(); em.getTransaction().begin(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/util/Umbrella.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/util/Umbrella.java index 298da5dfe0..382e3b1236 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/util/Umbrella.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/util/Umbrella.java @@ -1,6 +1,7 @@ package org.hibernate.jpa.test.util; import java.io.Serializable; import javax.persistence.Column; +import javax.persistence.Embeddable; import javax.persistence.EmbeddedId; import javax.persistence.Entity; @@ -30,7 +31,7 @@ public class Umbrella { public void setSize(int size) { this.size = size; } - + @Embeddable public static class PK implements Serializable { private String model; private String brand; diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/xml/XmlAttributeOverrideTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/xml/XmlAttributeOverrideTest.java index 018b197fb2..4d016f292f 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/xml/XmlAttributeOverrideTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/xml/XmlAttributeOverrideTest.java @@ -28,6 +28,7 @@ import javax.persistence.EntityManager; import org.junit.Test; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import static org.junit.Assert.assertEquals; @@ -55,6 +56,7 @@ public class XmlAttributeOverrideTest extends BaseEntityManagerFunctionalTestCas } @Test + @FailureExpectedWithNewMetamodel public void testDefaultEventListener() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -98,4 +100,9 @@ public class XmlAttributeOverrideTest extends BaseEntityManagerFunctionalTestCas "org/hibernate/jpa/test/xml/orm3.xml" }; } + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[]{CounterListener.class}; + } } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/xml/XmlTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/xml/XmlTest.java index 754adaa3f1..22c8a3b896 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/xml/XmlTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/xml/XmlTest.java @@ -34,10 +34,12 @@ import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.jpa.AvailableSettings; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.persister.entity.EntityPersister; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; /** * @author Emmanuel Bernard */ +@FailureExpectedWithNewMetamodel public class XmlTest extends BaseEntityManagerFunctionalTestCase { @Test public void testXmlMappingCorrectness() throws Exception { @@ -53,11 +55,6 @@ public class XmlTest extends BaseEntityManagerFunctionalTestCase { Assert.assertTrue(entityPersister.hasCache()); } - @Override - public Class[] getAnnotatedClasses() { - return new Class[0]; - } - protected void addConfigOptions(Map options) { options.put( AvailableSettings.SHARED_CACHE_MODE, SharedCacheMode.ENABLE_SELECTIVE ); } @@ -69,4 +66,9 @@ public class XmlTest extends BaseEntityManagerFunctionalTestCase { "org/hibernate/jpa/test/xml/orm2.xml", }; } + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[]{Article.class}; + } } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/xml/sequences/XmlTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/xml/sequences/XmlTest.java index 0f2e62d3fb..4f088354b1 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/xml/sequences/XmlTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/xml/sequences/XmlTest.java @@ -29,13 +29,16 @@ import org.junit.Test; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.jpa.test.xml.*; import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.RequiresDialectFeature; /** * @author Emmanuel Bernard */ @RequiresDialectFeature( DialectChecks.SupportsSequences.class ) +@FailureExpectedWithNewMetamodel public class XmlTest extends BaseEntityManagerFunctionalTestCase { @Test public void testXmlMappingCorrectness() throws Exception { @@ -50,4 +53,8 @@ public class XmlTest extends BaseEntityManagerFunctionalTestCase { "org/hibernate/jpa/test/xml/sequences/orm2.xml", }; } + @Override + protected Class[] getAnnotatedClasses() { + return new Class[]{ Article.class}; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/PropertiesGroupTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/PropertiesGroupTest.java index 7c09e7c644..6ab54b8b82 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/PropertiesGroupTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/PropertiesGroupTest.java @@ -1,14 +1,9 @@ package org.hibernate.envers.test.integration.components; -import java.io.File; -import java.net.URISyntaxException; -import java.net.URL; - import org.hibernate.Session; import org.junit.Assert; import org.junit.Test; -import org.hibernate.MappingException; import org.hibernate.envers.test.BaseEnversFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.components.UniquePropsEntity; diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/SingleNodeTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/SingleNodeTestCase.java index 88a29447bd..d0e429c994 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/SingleNodeTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/SingleNodeTestCase.java @@ -31,7 +31,6 @@ import org.infinispan.manager.EmbeddedCacheManager; import org.infinispan.test.fwk.TestCacheManagerFactory; import org.infinispan.util.logging.Log; import org.infinispan.util.logging.LogFactory; -import org.junit.Before; import org.hibernate.cache.infinispan.InfinispanRegionFactory; import org.hibernate.cache.spi.RegionFactory; diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/NaturalIdInvalidationTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/NaturalIdInvalidationTestCase.java index e79326f9f1..e15107c451 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/NaturalIdInvalidationTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/NaturalIdInvalidationTestCase.java @@ -18,15 +18,12 @@ import org.infinispan.notifications.cachelistener.event.CacheEntryVisitedEvent; import org.infinispan.util.logging.Log; import org.infinispan.util.logging.LogFactory; import org.jboss.util.collection.ConcurrentSet; -import org.junit.After; import org.junit.Test; import javax.transaction.TransactionManager; -import java.util.List; import java.util.Set; import java.util.concurrent.Callable; -import static org.infinispan.test.TestingUtil.tmpDirectory; import static org.infinispan.test.TestingUtil.withTx; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java index d005013be0..bd27297288 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java @@ -25,7 +25,6 @@ package org.hibernate.testing.junit4; import static org.junit.Assert.fail; -import java.io.InputStream; import java.sql.Blob; import java.sql.Clob; import java.sql.Connection; @@ -34,15 +33,12 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Properties; import org.hibernate.EmptyInterceptor; import org.hibernate.HibernateException; import org.hibernate.Interceptor; import org.hibernate.Session; import org.hibernate.boot.registry.BootstrapServiceRegistry; -import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; import org.hibernate.cache.spi.access.AccessType; import org.hibernate.cfg.AvailableSettings; @@ -56,7 +52,6 @@ import org.hibernate.engine.config.spi.ConfigurationService; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.internal.util.StringHelper; -import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.jdbc.AbstractReturningWork; import org.hibernate.jdbc.Work; import org.hibernate.mapping.Collection; @@ -71,7 +66,6 @@ import org.hibernate.metamodel.spi.binding.AbstractPluralAttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.Caching; import org.hibernate.metamodel.spi.binding.EntityBinding; -import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; import org.hibernate.testing.AfterClassOnce; import org.hibernate.testing.BeforeClassOnce; import org.hibernate.testing.OnExpectedFailure; @@ -87,47 +81,16 @@ import org.junit.Before; * * @author Steve Ebersole */ -public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { - public static final String VALIDATE_DATA_CLEANUP = "hibernate.test.validateDataCleanup"; - public static final String USE_NEW_METADATA_MAPPINGS = "hibernate.test.new_metadata_mappings"; +public abstract class BaseCoreFunctionalTestCase extends BaseFunctionalTestCase { - public static final Dialect DIALECT = Dialect.getDialect(); - - protected boolean isMetadataUsed; - private Configuration configuration; - private MetadataImplementor metadataImplementor; - private StandardServiceRegistryImpl serviceRegistry; private SessionFactoryImplementor sessionFactory; protected Session session; - protected static Dialect getDialect() { - return DIALECT; - } - protected Configuration configuration() { - return configuration; - } - protected MetadataImplementor metadata() { - return metadataImplementor; - } - protected EntityBinding getEntityBinding(Class clazz) { - return metadataImplementor.getEntityBinding( clazz.getName() ); - } - protected EntityBinding getRootEntityBinding(Class clazz) { - return metadataImplementor.getRootEntityBinding( clazz.getName() ); - } - - protected Iterator getCollectionBindings() { - return metadataImplementor.getCollectionBindings().iterator(); - } - - protected StandardServiceRegistryImpl serviceRegistry() { - return serviceRegistry; - } protected SessionFactoryImplementor sessionFactory() { return sessionFactory; @@ -166,10 +129,10 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { if ( isMetadataUsed ) { MetadataBuilder metadataBuilder = getMetadataBuilder( bootRegistry, serviceRegistry ); configMetadataBuilder(metadataBuilder, configuration); - metadataImplementor = (MetadataImplementor)metadataBuilder.build(); - afterConstructAndConfigureMetadata( metadataImplementor ); - applyCacheSettings(metadataImplementor); - SessionFactoryBuilder sessionFactoryBuilder = metadataImplementor.getSessionFactoryBuilder(); + metadata = (MetadataImplementor)metadataBuilder.build(); + afterConstructAndConfigureMetadata( metadata ); + applyCacheSettings( metadata ); + SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder(); configSessionFactoryBuilder(sessionFactoryBuilder, configuration); sessionFactory = ( SessionFactoryImplementor )sessionFactoryBuilder.build(); } @@ -181,9 +144,7 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { afterSessionFactoryBuilt(); } - protected boolean isMetadataUsed() { - return isMetadataUsed; - } + protected void rebuildSessionFactory() { if ( sessionFactory == null ) { return; @@ -196,14 +157,6 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { } - private MetadataImplementor buildMetadata( - BootstrapServiceRegistry bootRegistry, - StandardServiceRegistryImpl serviceRegistry) { - MetadataSources sources = new MetadataSources( bootRegistry ); - addMappings( sources ); - return (MetadataImplementor) sources.getMetadataBuilder( serviceRegistry ).build(); - } - protected void configMetadataBuilder(MetadataBuilder metadataBuilder, Configuration configuration) { //see if the naming strategy is the default one if ( configuration.getNamingStrategy() != EJB3NamingStrategy.INSTANCE ) { @@ -265,92 +218,6 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { protected void configure(Configuration configuration) { } - 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 = getXmlFiles(); - if ( xmlFiles != null ) { - for ( String xmlFile : xmlFiles ) { - InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile ); - configuration.addInputStream( is ); - } - } - } - - protected void addMappings(MetadataSources sources) { - String[] mappings = getMappings(); - if ( mappings != null ) { - for ( String mapping : mappings ) { - sources.addResource( - getBaseForMappings() + mapping - ); - } - } - Class[] annotatedClasses = getAnnotatedClasses(); - if ( annotatedClasses != null ) { - for ( Class annotatedClass : annotatedClasses ) { - sources.addAnnotatedClass( annotatedClass ); - } - } - String[] annotatedPackages = getAnnotatedPackages(); - if ( annotatedPackages != null ) { - for ( String annotatedPackage : annotatedPackages ) { - sources.addPackage( annotatedPackage ); - } - } - String[] xmlFiles = getXmlFiles(); - if ( xmlFiles != null ) { - for ( String xmlFile : xmlFiles ) { - InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile ); - sources.addInputStream( is ); - } - } - } - - 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[] getXmlFiles() { - // todo : rename to getOrmXmlFiles() - return NO_MAPPINGS; - } - protected void applyCacheSettings(MetadataImplementor metadataImplementor){ if( StringHelper.isEmpty(getCacheConcurrencyStrategy())){ return; @@ -441,36 +308,11 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { protected void afterConfigurationBuilt(Mappings mappings, Dialect dialect) { } - protected BootstrapServiceRegistry buildBootstrapServiceRegistry() { - final BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder(); - prepareBootstrapRegistryBuilder( builder ); - return builder.build(); - } - protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) { - } - - protected StandardServiceRegistryImpl buildServiceRegistry(BootstrapServiceRegistry bootRegistry, Configuration configuration) { - Properties properties = new Properties(); - properties.putAll( configuration.getProperties() ); - Environment.verifyProperties( properties ); - ConfigurationHelper.resolvePlaceHolders( properties ); - - StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder( bootRegistry ).applySettings( properties ); - prepareBasicRegistryBuilder( registryBuilder ); - return (StandardServiceRegistryImpl) registryBuilder.build(); - } - - protected void prepareBasicRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) { - } protected void afterSessionFactoryBuilt() { } - protected boolean createSchema() { - return true; - } - /** * Feature supported only by H2 dialect. * @return Provide not empty name to create second schema. diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseFunctionalTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseFunctionalTestCase.java new file mode 100644 index 0000000000..ff438e659c --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseFunctionalTestCase.java @@ -0,0 +1,179 @@ +package org.hibernate.testing.junit4; + +import java.io.InputStream; +import java.util.Iterator; +import java.util.Properties; + +import org.hibernate.boot.registry.BootstrapServiceRegistry; +import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; +import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.Environment; +import org.hibernate.dialect.Dialect; +import org.hibernate.internal.util.config.ConfigurationHelper; +import org.hibernate.metamodel.MetadataSources; +import org.hibernate.metamodel.spi.MetadataImplementor; +import org.hibernate.metamodel.spi.binding.EntityBinding; +import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; + +/** + * @author Strong Liu + */ +public class BaseFunctionalTestCase extends BaseUnitTestCase { + public static final String VALIDATE_DATA_CLEANUP = "hibernate.test.validateDataCleanup"; + public static final String USE_NEW_METADATA_MAPPINGS = MetadataSources.USE_NEW_METADATA_MAPPINGS; + public static final Dialect DIALECT = Dialect.getDialect(); + protected static final String[] NO_MAPPINGS = new String[0]; + protected static final Class[] NO_CLASSES = new Class[0]; + protected Configuration configuration; + protected MetadataImplementor metadata; + protected StandardServiceRegistryImpl serviceRegistry; + protected boolean isMetadataUsed; + + protected static Dialect getDialect() { + return DIALECT; + } + //----------------------- configuration properties + + protected boolean createSchema() { + return true; + } + + protected Configuration configuration() { + return configuration; + } + + protected MetadataImplementor metadata() { + return metadata; + } + + protected boolean isMetadataUsed() { + return isMetadataUsed; + } + + //----------------------- services and service registry + protected BootstrapServiceRegistry buildBootstrapServiceRegistry() { + final BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder(); + prepareBootstrapServiceRegistryBuilder( builder ); + return builder.build(); + } + + protected StandardServiceRegistryImpl serviceRegistry() { + return serviceRegistry; + } + protected StandardServiceRegistryImpl buildServiceRegistry(BootstrapServiceRegistry bootRegistry, Configuration configuration) { + Properties properties = new Properties(); + properties.putAll( configuration.getProperties() ); + Environment.verifyProperties( properties ); + ConfigurationHelper.resolvePlaceHolders( properties ); + + StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder( bootRegistry ).applySettings( properties ); + prepareStandardServiceRegistryBuilder( registryBuilder ); + return (StandardServiceRegistryImpl) registryBuilder.build(); + } + + protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) { + } + + protected void prepareBootstrapServiceRegistryBuilder(BootstrapServiceRegistryBuilder builder) { + } + + + //----------------------- source mappings + 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 = getXmlFiles(); + if ( xmlFiles != null ) { + for ( String xmlFile : xmlFiles ) { + InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile ); + configuration.addInputStream( is ); + } + } + } + + protected void addMappings(MetadataSources sources) { + String[] mappings = getMappings(); + if ( mappings != null ) { + for ( String mapping : mappings ) { + sources.addResource( + getBaseForMappings() + mapping + ); + } + } + Class[] annotatedClasses = getAnnotatedClasses(); + if ( annotatedClasses != null ) { + for ( Class annotatedClass : annotatedClasses ) { + sources.addAnnotatedClass( annotatedClass ); + } + } + String[] annotatedPackages = getAnnotatedPackages(); + if ( annotatedPackages != null ) { + for ( String annotatedPackage : annotatedPackages ) { + sources.addPackage( annotatedPackage ); + } + } + String[] xmlFiles = getXmlFiles(); + if ( xmlFiles != null ) { + for ( String xmlFile : xmlFiles ) { + InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile ); + sources.addInputStream( is ); + } + } + } + + protected String[] getMappings() { + return NO_MAPPINGS; + } + + protected String getBaseForMappings() { + return "org/hibernate/test/"; + } + + protected Class[] getAnnotatedClasses() { + return NO_CLASSES; + } + + protected String[] getAnnotatedPackages() { + return NO_MAPPINGS; + } + + protected String[] getXmlFiles() { + // todo : rename to getOrmXmlFiles() + return NO_MAPPINGS; + } + //------------------------------------------- + + protected EntityBinding getEntityBinding(Class clazz) { + return metadata.getEntityBinding( clazz.getName() ); + } + + protected EntityBinding getRootEntityBinding(Class clazz) { + return metadata.getRootEntityBinding( clazz.getName() ); + } + + protected Iterator getCollectionBindings() { + return metadata.getCollectionBindings().iterator(); + } + +}