diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java index 036b1218a2..1bd76ebfaa 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java @@ -1638,7 +1638,7 @@ public List list(Criteria criteria) throws HibernateException { int size = implementors.length; CriteriaLoader[] loaders = new CriteriaLoader[size]; - Set spaces = new HashSet(); + Set spaces = new HashSet(); for( int i=0; i querySpaces; private final Type[] resultTypes; //the user visible aliases, which are unknown to the superclass, //these are not the actual "physical" SQL aliases @@ -189,7 +190,7 @@ private Object[] toResultRow(Object[] row) { } } - public Set getQuerySpaces() { + public Set getQuerySpaces() { return querySpaces; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/Metadata.java b/hibernate-core/src/main/java/org/hibernate/metamodel/Metadata.java index 43924bccae..5c8f11d171 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/Metadata.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/Metadata.java @@ -44,7 +44,9 @@ import org.hibernate.metamodel.spi.binding.FetchProfile; import org.hibernate.metamodel.spi.binding.IdGenerator; import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; +import org.hibernate.metamodel.spi.binding.SecondaryTable; import org.hibernate.metamodel.spi.binding.TypeDefinition; +import org.hibernate.metamodel.spi.relational.Identifier; import org.hibernate.type.BasicType; /** @@ -55,20 +57,20 @@ public interface Metadata { * Exposes the options used to produce a {@link Metadata} instance. */ public static interface Options { - public StandardServiceRegistry getServiceRegistry(); + StandardServiceRegistry getServiceRegistry(); - public MetadataSourceProcessingOrder getMetadataSourceProcessingOrder(); - public NamingStrategy getNamingStrategy(); - public EntityResolver getEntityResolver(); - public SharedCacheMode getSharedCacheMode(); - public AccessType getDefaultAccessType(); - public boolean useNewIdentifierGenerators(); - public boolean isGloballyQuotedIdentifiers(); - public String getDefaultSchemaName(); - public String getDefaultCatalogName(); - public MultiTenancyStrategy getMultiTenancyStrategy(); - public IndexView getJandexView(); - public List getBasicTypeRegistrations(); + MetadataSourceProcessingOrder getMetadataSourceProcessingOrder(); + NamingStrategy getNamingStrategy(); + EntityResolver getEntityResolver(); + SharedCacheMode getSharedCacheMode(); + AccessType getDefaultAccessType(); + boolean useNewIdentifierGenerators(); + boolean isGloballyQuotedIdentifiers(); + String getDefaultSchemaName(); + String getDefaultCatalogName(); + MultiTenancyStrategy getMultiTenancyStrategy(); + IndexView getJandexView(); + List getBasicTypeRegistrations(); } /** @@ -76,14 +78,14 @@ public static interface Options { * * @return The options. */ - public Options getOptions(); + Options getOptions(); /** * Get the builder for {@link SessionFactory} instances based on this metamodel, * * @return The builder for {@link SessionFactory} instances. */ - public SessionFactoryBuilder getSessionFactoryBuilder(); + SessionFactoryBuilder getSessionFactoryBuilder(); /** * Short-hand form of building a {@link SessionFactory} through the builder without any additional @@ -91,40 +93,31 @@ public static interface Options { * * @return THe built SessionFactory. */ - public SessionFactory buildSessionFactory(); + SessionFactory buildSessionFactory(); - public Iterable getEntityBindings(); - public EntityBinding getEntityBinding(String entityName); + EntityBinding getEntityBinding(String entityName); /** * Get the "root" entity binding * @param entityName * @return the "root entity binding; simply returns entityBinding if it is the root entity binding */ - public EntityBinding getRootEntityBinding(String entityName); + EntityBinding getRootEntityBinding(String entityName); + IdGenerator getIdGenerator(String name); + boolean hasTypeDefinition(String name); + TypeDefinition getTypeDefinition(String name); - public Iterable getCollectionBindings(); + Iterable getCollectionBindings(); + Iterable getEntityBindings(); + Iterable getTypeDefinitions(); + Iterable getNamedQueryDefinitions(); + Iterable getNamedNativeQueryDefinitions(); + Iterable getFetchProfiles(); - public boolean hasTypeDefinition(String name); - - public TypeDefinition getTypeDefinition(String name); - - public Iterable getTypeDefinitions(); - - public Map getFilterDefinitions(); - - public Iterable getNamedQueryDefinitions(); - - public Map getNamedEntityGraphMap(); - - public Iterable getNamedNativeQueryDefinitions(); - - public Map getResultSetMappingDefinitions(); - - public Map getImports(); - - public Iterable getFetchProfiles(); - - public IdGenerator getIdGenerator(String name); + Map getSecondaryTables(); + Map getFilterDefinitions(); + Map getNamedEntityGraphs(); + Map getResultSetMappingDefinitions(); + Map getImports(); } 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 76668e514d..be5b266062 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 @@ -781,13 +781,16 @@ private void bindDiscriminator( if ( discriminatorValue != null ) { rootEntityBinding.setDiscriminatorMatchValue( discriminatorValue ); } - else if ( !Modifier.isAbstract( - bindingContext().locateClassByName( rootEntitySource.getEntityName() ) - .getModifiers() - ) ) { + else +// if ( !Modifier.isAbstract( +// bindingContext().locateClassByName( rootEntitySource.getEntityName() ) +// .getModifiers() +// ) ) + { // Use the class name as a default if no discriminator value. // However, skip abstract classes -- obviously no discriminators there. - rootEntityBinding.setDiscriminatorMatchValue( rootEntitySource.getEntityName() ); + // But this is not correct, since for single table entity hierarchy, even the root class is abstract, it still should has discriminator + rootEntityBinding.setDiscriminatorMatchValue( StringHelper.unqualify( rootEntitySource.getEntityName() ) ); } // Configure discriminator hibernate type typeHelper.bindDiscriminatorType( discriminator, value ); @@ -969,14 +972,19 @@ private void bindSecondaryTables( targetColumns ); SecondaryTable secondaryTable = new SecondaryTable( table, foreignKey ); + if(secondaryTableSource.getFetchStyle()!=null) secondaryTable.setFetchStyle( secondaryTableSource.getFetchStyle() ); secondaryTable.setInverse( secondaryTableSource.isInverse() ); secondaryTable.setOptional( secondaryTableSource.isOptional() ); secondaryTable.setCascadeDeleteEnabled( secondaryTableSource.isCascadeDeleteEnabled() ); + secondaryTable.setCustomDelete( secondaryTableSource.getCustomSqlDelete() ); + secondaryTable.setCustomInsert( secondaryTableSource.getCustomSqlInsert() ); + secondaryTable.setCustomUpdate( secondaryTableSource.getCustomSqlUpdate() ); if ( secondaryTable.isCascadeDeleteEnabled() ) { foreignKey.setDeleteRule( ForeignKey.ReferentialAction.CASCADE ); } entityBinding.addSecondaryTable( secondaryTable ); + metadata.addSecondaryTable( secondaryTable ); } } 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 53c7434f71..ef9399b3c5 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 @@ -87,11 +87,13 @@ import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeKeyBinding; import org.hibernate.metamodel.spi.binding.RelationalValueBinding; +import org.hibernate.metamodel.spi.binding.SecondaryTable; import org.hibernate.metamodel.spi.binding.TypeDefinition; import org.hibernate.metamodel.spi.domain.BasicType; import org.hibernate.metamodel.spi.domain.SingularAttribute; import org.hibernate.metamodel.spi.domain.Type; import org.hibernate.metamodel.spi.relational.Database; +import org.hibernate.metamodel.spi.relational.Identifier; import org.hibernate.metamodel.spi.relational.Schema; import org.hibernate.metamodel.spi.relational.Table; import org.hibernate.metamodel.spi.source.FilterDefinitionSource; @@ -136,22 +138,24 @@ public class MetadataImpl implements MetadataImplementor, Serializable { private final ObjectNameNormalizer nameNormalizer; private final Map typeDefinitionMap = new HashMap(); - private Map filterDefinitionMap = new HashMap(); + private final Map filterDefinitionMap = new HashMap(); - private Map entityBindingMap = new HashMap(); - private Map collectionBindingMap = new HashMap(); - private Map fetchProfiles = new HashMap(); - private Map imports = new HashMap(); - private Map idGenerators = new HashMap(); - private Map namedQueryDefs = new HashMap(); - private Map namedNativeQueryDefs = new HashMap(); - private Map resultSetMappings = new HashMap(); + private final Map entityBindingMap = new HashMap(); + private final Map collectionBindingMap = new HashMap(); + private final Map fetchProfiles = new HashMap(); + private final Map imports = new HashMap(); + private final Map idGenerators = new HashMap(); + private final Map namedQueryDefs = new HashMap(); + private final Map namedNativeQueryDefs = new HashMap(); + private final Map resultSetMappings = new HashMap(); private final Map namedEntityGraphMap = new HashMap( ); + private final Map secondaryTableMap = new HashMap( ); private boolean globallyQuotedIdentifiers = false; public MetadataImpl(MetadataSources metadataSources, Options options) { this.serviceRegistry = options.getServiceRegistry(); + this.classLoaderService = serviceRegistry.getService( ClassLoaderService.class ); this.options = options; this.identifierGeneratorFactory = serviceRegistry.getService( MutableIdentifierGeneratorFactory.class ); this.database = new Database( options, serviceRegistry.getService( JdbcServices.class ).getJdbcEnvironment() ); @@ -189,7 +193,6 @@ protected boolean isUseQuotedIdentifiersGlobally() { }; } - this.classLoaderService = serviceRegistry.getService( ClassLoaderService.class ); // this.persisterClassResolverService = new ValueHolder( // new ValueHolder.DeferredInitializer() { // @Override @@ -387,7 +390,7 @@ public void addNamedEntityGraph(NamedEntityGraphDefinition definition) { } @Override - public Map getNamedEntityGraphMap() { + public Map getNamedEntityGraphs() { return namedEntityGraphMap; } @@ -728,6 +731,16 @@ public void addEntity(EntityBinding entityBinding) { } } + @Override + public void addSecondaryTable(SecondaryTable secondaryTable) { + secondaryTableMap.put( secondaryTable.getSecondaryTableReference().getLogicalName(), secondaryTable ); + } + + @Override + public Map getSecondaryTables() { + return secondaryTableMap; + } + public PluralAttributeBinding getCollection(String collectionRole) { return collectionBindingMap.get( collectionRole ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/SecondaryTableSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/SecondaryTableSourceImpl.java index 2ebccf3caa..ac76850687 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/SecondaryTableSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/SecondaryTableSourceImpl.java @@ -28,6 +28,7 @@ import org.hibernate.engine.FetchStyle; import org.hibernate.metamodel.internal.source.annotations.attribute.PrimaryKeyJoinColumn; +import org.hibernate.metamodel.spi.binding.CustomSQL; import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.metamodel.spi.relational.Value; import org.hibernate.metamodel.spi.source.ColumnSource; @@ -80,27 +81,42 @@ public List getPrimaryKeyColumnSources() { @Override public String getComment() { - return null; //To change body of implemented methods use File | Settings | File Templates. + return null; } @Override public FetchStyle getFetchStyle() { - return null; //To change body of implemented methods use File | Settings | File Templates. + return null; } @Override public boolean isInverse() { - return false; //To change body of implemented methods use File | Settings | File Templates. + return false; } @Override public boolean isOptional() { - return false; //To change body of implemented methods use File | Settings | File Templates. + return true; } @Override public boolean isCascadeDeleteEnabled() { - return false; //To change body of implemented methods use File | Settings | File Templates. + return false; + } + + @Override + public CustomSQL getCustomSqlDelete() { + return null; + } + + @Override + public CustomSQL getCustomSqlInsert() { + return null; + } + + @Override + public CustomSQL getCustomSqlUpdate() { + return null; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/TableProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/TableProcessor.java index 72371d5bae..e441cc0435 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/TableProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/TableProcessor.java @@ -29,12 +29,17 @@ import org.jboss.logging.Logger; import org.hibernate.AnnotationException; +import org.hibernate.MappingException; +import org.hibernate.annotations.FetchMode; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext; +import org.hibernate.metamodel.internal.source.annotations.util.AnnotationParserHelper; +import org.hibernate.metamodel.internal.source.annotations.util.EnumConversionHelper; import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames; import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; import org.hibernate.metamodel.spi.MetadataImplementor; +import org.hibernate.metamodel.spi.binding.SecondaryTable; import org.hibernate.metamodel.spi.relational.Column; import org.hibernate.metamodel.spi.relational.Index; import org.hibernate.metamodel.spi.relational.ObjectName; @@ -83,11 +88,19 @@ private static void bind(MetadataImplementor metadata, AnnotationInstance tableA Schema schema = metadata.getDatabase().getSchema( objectName.getCatalog(), objectName.getSchema() ); Table table = schema.locateTable( objectName.getName() ); if ( table != null ) { - bindHibernateTableAnnotation( table, tableAnnotation ); + boolean isSecondaryTable = metadata.getSecondaryTables().containsKey( table.getLogicalName() ); + bindHibernateTableAnnotation( table, tableAnnotation,isSecondaryTable, metadata ); + } + else { + throw new MappingException( "Can't find table[" + tableName + "] from Annotation @Table" ); } } - private static void bindHibernateTableAnnotation(Table table, AnnotationInstance tableAnnotation) { + private static void bindHibernateTableAnnotation( + final Table table, + final AnnotationInstance tableAnnotation, + final boolean isSecondaryTable, + final MetadataImplementor metadata) { for ( AnnotationInstance indexAnnotation : JandexHelper.getValue( tableAnnotation, "indexes", @@ -99,10 +112,61 @@ private static void bindHibernateTableAnnotation(Table table, AnnotationInstance if ( StringHelper.isNotEmpty( comment ) ) { table.addComment( comment.trim() ); } + if ( !isSecondaryTable ) { + return; + } + SecondaryTable secondaryTable = metadata.getSecondaryTables().get( table.getLogicalName() ); + if ( tableAnnotation.value( "fetch" ) != null ) { + FetchMode fetchMode = JandexHelper.getEnumValue( tableAnnotation, "fetch", FetchMode.class ); + secondaryTable.setFetchStyle( EnumConversionHelper.annotationFetchModeToFetchStyle( fetchMode ) ); + } + if ( tableAnnotation.value( "inverse" ) != null ) { + secondaryTable.setInverse( tableAnnotation.value( "inverse" ).asBoolean() ); + } + if ( tableAnnotation.value( "optional" ) != null ) { + secondaryTable.setOptional( tableAnnotation.value( "optional" ).asBoolean() ); + } + + if ( tableAnnotation.value( "sqlInsert" ) != null ) { + secondaryTable.setCustomInsert( + AnnotationParserHelper.createCustomSQL( + tableAnnotation.value( "sqlInsert" ) + .asNested() + ) + ); + } + if ( tableAnnotation.value( "sqlUpdate" ) != null ) { + secondaryTable.setCustomUpdate( + AnnotationParserHelper.createCustomSQL( + tableAnnotation.value( "sqlUpdate" ) + .asNested() + ) + ); + + } + if ( tableAnnotation.value( "sqlDelete" ) != null ) { + secondaryTable.setCustomDelete( + AnnotationParserHelper.createCustomSQL( + tableAnnotation.value( "sqlDelete" ) + .asNested() + ) + ); + } + // TODO: ForeignKey is not binded right now, because constrint name is not modifyable after it is set + // another option would be create something like tableDefinition and look up it when we bind table / secondary table + +// if ( tableAnnotation.value( "foreignKey" ) != null ) { +// AnnotationInstance foreignKeyAnnotation = tableAnnotation.value( "foreignKey" ).asNested(); +// if ( foreignKeyAnnotation.value( "name" ) != null ) { +// secondaryTable.getForeignKeyReference().setName( foreignKeyAnnotation.value( "name" ).asString() ); +// } +// } + + } private static void bindIndexAnnotation(Table table, AnnotationInstance tableAnnotation, AnnotationInstance indexAnnotation) { - String indexName = JandexHelper.getValue( tableAnnotation, "appliesTo", String.class ); + String indexName = JandexHelper.getValue( indexAnnotation, "name", String.class ); String[] columnNames = JandexHelper.getValue( indexAnnotation, "columnNames", String[].class ); if ( columnNames == null ) { LOG.noColumnsSpecifiedForIndex( indexName, table.toLoggableString() ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/AnnotationParserHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/AnnotationParserHelper.java index e194385416..1e2ffad6ab 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/AnnotationParserHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/AnnotationParserHelper.java @@ -61,7 +61,7 @@ public static CustomSQL processCustomSqlAnnotation(DotName annotationName, return createCustomSQL( sqlAnnotation ); } - private static CustomSQL createCustomSQL(AnnotationInstance customSqlAnnotation) { + public static CustomSQL createCustomSQL(AnnotationInstance customSqlAnnotation) { if ( customSqlAnnotation == null ) { return null; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JPADotNames.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JPADotNames.java index d3d0409e38..91f128e6b1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JPADotNames.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JPADotNames.java @@ -57,6 +57,7 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.IdClass; +import javax.persistence.Index; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; @@ -153,6 +154,7 @@ public interface JPADotNames { DotName GENERATED_VALUE = DotName.createSimple( GeneratedValue.class.getName() ); DotName ID = DotName.createSimple( Id.class.getName() ); DotName ID_CLASS = DotName.createSimple( IdClass.class.getName() ); + DotName INDEX = DotName.createSimple( Index.class.getName() ); DotName INHERITANCE = DotName.createSimple( Inheritance.class.getName() ); DotName INHERITANCE_TYPE = DotName.createSimple( InheritanceType.class.getName() ); DotName JOIN_COLUMN = DotName.createSimple( JoinColumn.class.getName() ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AbstractMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AbstractMocker.java index 9ed336af1e..6ffd1979e0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AbstractMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AbstractMocker.java @@ -100,8 +100,7 @@ protected AnnotationInstance parserUniqueConstraint(JaxbUniqueConstraint uniqueC List annotationValueList = new ArrayList(); MockHelper.stringValue( "name", uniqueConstraint.getName(), annotationValueList ); MockHelper.stringArrayValue( "columnNames", uniqueConstraint.getColumnName(), annotationValueList ); - return - create( UNIQUE_CONSTRAINT, target, + return create( UNIQUE_CONSTRAINT, target, annotationValueList ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/SecondaryTableSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/SecondaryTableSourceImpl.java index d38b5a644c..d23704b991 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/SecondaryTableSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/SecondaryTableSourceImpl.java @@ -31,6 +31,7 @@ import org.hibernate.jaxb.spi.hbm.JaxbFetchStyleAttribute; import org.hibernate.jaxb.spi.hbm.JaxbJoinElement; import org.hibernate.jaxb.spi.hbm.JaxbOnDeleteAttribute; +import org.hibernate.metamodel.spi.binding.CustomSQL; import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.metamodel.spi.relational.Value; import org.hibernate.metamodel.spi.source.ColumnSource; @@ -145,6 +146,22 @@ public JoinColumnResolutionDelegate getForeignKeyTargetColumnResolutionDelegate( return fkJoinColumnResolutionDelegate; } + @Override + public CustomSQL getCustomSqlInsert() { + return Helper.buildCustomSql( joinElement.getSqlInsert() ); + } + + @Override + public CustomSQL getCustomSqlUpdate() { + return Helper.buildCustomSql( joinElement.getSqlUpdate() ); + } + + @Override + public CustomSQL getCustomSqlDelete() { + return Helper.buildCustomSql( joinElement.getSqlDelete() ); + } + + public String getLogicalTableNameForContainedColumns() { return TableSource.class.isInstance( joinTable ) ? ( (TableSource) joinTable ).getExplicitTableName() diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetadataImplementor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetadataImplementor.java index 745f6edc91..2f05998edc 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetadataImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetadataImplementor.java @@ -35,6 +35,7 @@ import org.hibernate.metamodel.spi.binding.FetchProfile; import org.hibernate.metamodel.spi.binding.IdGenerator; import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; +import org.hibernate.metamodel.spi.binding.SecondaryTable; import org.hibernate.metamodel.spi.binding.TypeDefinition; import org.hibernate.metamodel.spi.relational.Database; import org.hibernate.metamodel.spi.source.BindingContext; @@ -56,6 +57,8 @@ public interface MetadataImplementor extends Metadata, BindingContext, Mapping { public void addEntity(EntityBinding entityBinding); + public void addSecondaryTable(SecondaryTable secondaryTable); + public void addCollection(PluralAttributeBinding collectionBinding); public void addFetchProfile(FetchProfile profile); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityBinding.java index 50c879ed86..162baa4623 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityBinding.java @@ -804,8 +804,7 @@ public AttributeBinding[] getNonIdEntitiesAttributeBindingClosure() { } public boolean isClassOrSuperclassSecondaryTable(SecondaryTable secondaryTable) { - String secondaryTableName = secondaryTable.getSecondaryTableReference().getLogicalName().getText(); - return secondaryTables.containsKey( Identifier.toIdentifier( secondaryTableName ) ) || + return secondaryTables.containsKey( secondaryTable.getSecondaryTableReference().getLogicalName() ) || ( superEntityBinding != null && superEntityBinding.isClassOrSuperclassSecondaryTable( secondaryTable ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/SecondaryTable.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/SecondaryTable.java index 61065cfddb..deeaeeb209 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/SecondaryTable.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/SecondaryTable.java @@ -33,10 +33,13 @@ public class SecondaryTable { private final TableSpecification secondaryTableReference; private final ForeignKey foreignKeyReference; - private FetchStyle fetchStyle; - private boolean isInverse; - private boolean isOptional; + private FetchStyle fetchStyle = FetchStyle.JOIN; + private boolean isInverse = false; + private boolean isOptional = true; private boolean isCascadeDeleteEnabled; + private CustomSQL customInsert; + private CustomSQL customUpdate; + private CustomSQL customDelete; public SecondaryTable(TableSpecification secondaryTableReference, ForeignKey foreignKeyReference) { this.secondaryTableReference = secondaryTableReference; @@ -86,4 +89,28 @@ public boolean isLazy() { // TODO: need to check attribute bindings using this table return false; } + + public CustomSQL getCustomDelete() { + return customDelete; + } + + public void setCustomDelete(CustomSQL customDelete) { + this.customDelete = customDelete; + } + + public CustomSQL getCustomInsert() { + return customInsert; + } + + public void setCustomInsert(CustomSQL customInsert) { + this.customInsert = customInsert; + } + + public CustomSQL getCustomUpdate() { + return customUpdate; + } + + public void setCustomUpdate(CustomSQL customUpdate) { + this.customUpdate = customUpdate; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/LocalBindingContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/LocalBindingContext.java index f6aafbcdeb..1c977812f9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/LocalBindingContext.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/LocalBindingContext.java @@ -32,4 +32,5 @@ public interface LocalBindingContext extends BindingContext { public Origin getOrigin(); public MappingException makeMappingException(String message); public MappingException makeMappingException(String message, Exception cause); + } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/SecondaryTableSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/SecondaryTableSource.java index a411e53a6e..548b6f2b15 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/SecondaryTableSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/SecondaryTableSource.java @@ -26,6 +26,7 @@ import java.util.List; import org.hibernate.engine.FetchStyle; +import org.hibernate.metamodel.spi.binding.CustomSQL; /** * @author Steve Ebersole @@ -56,4 +57,25 @@ public interface SecondaryTableSource extends ForeignKeyContributingSource { public boolean isOptional(); public boolean isCascadeDeleteEnabled(); + + /** + * Obtain the custom SQL to be used for inserts for this entity + * + * @return The custom insert SQL + */ + public CustomSQL getCustomSqlInsert(); + + /** + * Obtain the custom SQL to be used for updates for this entity + * + * @return The custom update SQL + */ + public CustomSQL getCustomSqlUpdate(); + + /** + * Obtain the custom SQL to be used for deletes for this entity + * + * @return The custom delete SQL + */ + public CustomSQL getCustomSqlDelete(); } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index cad3fbd0bd..9c08fc2cdf 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -3800,22 +3800,26 @@ protected boolean isSubclassTableLazy(int j) { return false; } - protected JoinFragment createJoin(String name, boolean innerJoin, boolean includeSubclasses) { - final String[] idCols = StringHelper.qualify( name, getIdentifierColumnNames() ); //all joins join to the pk of the driving table + protected JoinFragment createJoin(final String name, final boolean innerJoin, final boolean includeSubclasses) { final JoinFragment join = getFactory().getDialect().createOuterJoinFragment(); final int tableSpan = getSubclassTableSpan(); + final String[] idCols = StringHelper.qualify( name, getIdentifierColumnNames() ); //all joins join to the pk of the driving table for ( int j = 1; j < tableSpan; j++ ) { //notice that we skip the first table; it is the driving table! - final boolean joinIsIncluded = isClassOrSuperclassTable( j ) || + final boolean classOrSupperClassTable = isClassOrSuperclassTable( j ); + final boolean joinIsIncluded = classOrSupperClassTable || ( includeSubclasses && !isSubclassTableSequentialSelect( j ) && !isSubclassTableLazy( j ) ); if ( joinIsIncluded ) { - join.addJoin( getSubclassTableName( j ), + final JoinType joinType = innerJoin && classOrSupperClassTable && !isInverseTable( j ) && !isNullableTable( j ) ? + JoinType.INNER_JOIN : //we can inner join to superclass tables (the row MUST be there) + JoinType.LEFT_OUTER_JOIN; //we can never inner join to subclass tables + + join.addJoin( + getSubclassTableName( j ), generateTableAlias( name, j ), idCols, getSubclassTableKeyColumns( j ), - innerJoin && isClassOrSuperclassTable( j ) && !isInverseTable( j ) && !isNullableTable( j ) ? - JoinType.INNER_JOIN : //we can inner join to superclass tables (the row MUST be there) - JoinType.LEFT_OUTER_JOIN //we can never inner join to subclass tables - ); + joinType + ); } } return join; diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java index 66fee2aab1..a9b41e2b84 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java @@ -267,8 +267,9 @@ public SingleTableEntityPersister( joinIter = persistentClass.getSubclassJoinClosureIterator(); while ( joinIter.hasNext() ) { Join join = (Join) joinIter.next(); - isConcretes.add( persistentClass.isClassOrSuperclassJoin(join) ); - isDeferreds.add( join.isSequentialSelect() ); + isConcretes.add( persistentClass.isClassOrSuperclassJoin(join) ); //if the secondary table is defined in the current class or its super class + isDeferreds.add( join.isSequentialSelect() ); //defaults to 'false' unless there is a org.hibernate.annotations.Table defines its fetch model to others then JOIN + //see org.hibernate.cfg.annotations.EntityBinder#addJoin isInverses.add( join.isInverse() ); isNullables.add( join.isOptional() ); isLazies.add( lazyAvailable && join.isLazy() ); @@ -515,9 +516,9 @@ public SingleTableEntityPersister( cascadeDeleteEnabled[j] = join.isCascadeDeleteEnabled() && factory.getDialect().supportsCascadeDelete(); - initializeCustomSql( entityBinding.getCustomInsert(), j, customSQLInsert, insertCallable, insertResultCheckStyles ); - initializeCustomSql( entityBinding.getCustomUpdate(), j, customSQLUpdate, updateCallable, updateResultCheckStyles ); - initializeCustomSql( entityBinding.getCustomDelete(), j, customSQLDelete, deleteCallable, deleteResultCheckStyles ); + initializeCustomSql( join.getCustomInsert(), j, customSQLInsert, insertCallable, insertResultCheckStyles ); + initializeCustomSql( join.getCustomUpdate(), j, customSQLUpdate, updateCallable, updateResultCheckStyles ); + initializeCustomSql( join.getCustomDelete(), j, customSQLDelete, deleteCallable, deleteResultCheckStyles ); final List joinColumns = join.getForeignKeyReference().getSourceColumns(); keyColumnNames[j] = new String[ joinColumns.size() ]; @@ -566,9 +567,7 @@ public SingleTableEntityPersister( isInverses.add( join.isInverse() ); isNullables.add( join.isOptional() ); isLazies.add( lazyAvailable && join.isLazy() ); - if ( isDeferred && !isConcrete ) { - hasDeferred = true; - } + hasDeferred = isDeferred && !isConcrete; subclassTables.add( join.getSecondaryTableReference().getQualifiedName( factory.getDialect() ) ); final List joinColumns = join.getForeignKeyReference().getSourceColumns(); String[] keyCols = new String[ joinColumns.size() ]; @@ -686,15 +685,16 @@ else if ( entityBinding.isDiscriminatorMatchValueNotNull() ) { ArrayList propertyJoinNumbers = new ArrayList(); for ( AttributeBinding attributeBinding : entityBinding.getNonIdEntitiesAttributeBindingClosure() ) { + final String entityName = attributeBinding.getContainer().seekEntityBinding().getEntityName(); + String path = StringHelper.isEmpty( attributeBinding.getContainer().getPathBase() ) ? + entityName + '.' + attributeBinding.getAttribute().getName() : + entityName + '.' + attributeBinding.getContainer().getPathBase() + '.' + attributeBinding.getAttribute().getName(); if ( attributeBinding.getAttribute().isSingular() ) { SingularAttributeBinding singularAttributeBinding = (SingularAttributeBinding) attributeBinding; int join = entityBinding.getSecondaryTableNumber( singularAttributeBinding ); propertyJoinNumbers.add( join ); // We need the name of the actual entity that contains this attribute binding. - final String entityName = attributeBinding.getContainer().seekEntityBinding().getEntityName(); - String path = StringHelper.isEmpty( attributeBinding.getContainer().getPathBase() ) ? - entityName + '.' + attributeBinding.getAttribute().getName() : - entityName + '.' + attributeBinding.getContainer().getPathBase() + '.' + attributeBinding.getAttribute().getName(); + //TODO it should be folder.children but now it is ".children" propertyTableNumbersByNameAndSubclass.put( path, join ); for ( RelationalValueBinding relationalValueBinding : singularAttributeBinding.getRelationalValueBindings() ) { if ( DerivedValue.class.isInstance( relationalValueBinding.getValue() ) ) { @@ -707,10 +707,7 @@ else if ( entityBinding.isDiscriminatorMatchValueNotNull() ) { } else { propertyJoinNumbers.add( 0 ); - propertyTableNumbersByNameAndSubclass.put( - attributeBinding.getContainer().getPathBase() + '.' + attributeBinding.getAttribute().getName(), - 0 - ); + propertyTableNumbersByNameAndSubclass.put( path, 0 ); } } subclassColumnTableNumberClosure = ArrayHelper.toIntArray(columnJoinNumbers); @@ -1059,7 +1056,7 @@ public String getPropertyTableName(String propertyName) { } return qualifiedTableNames[ propertyTableNumbers[ index ] ]; } - + @Override public void postInstantiate() { super.postInstantiate(); if (hasSequentialSelects) { diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/InheritanceBindingTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/InheritanceBindingTest.java index cc5a9fa7a2..bbe7fa17bd 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/InheritanceBindingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/InheritanceBindingTest.java @@ -37,6 +37,7 @@ import org.hibernate.annotations.DiscriminatorFormula; import org.hibernate.annotations.DiscriminatorOptions; +import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.EntityDiscriminator; @@ -168,7 +169,7 @@ public void testRootPolymporphism() { EntityBinding subclassOfSubclassEntityBinding = getEntityBinding( SubclassOfSubclassOfSingleTableInheritance.class ); assertTrue( rootEntityBinding.isRoot() ); - assertEquals( rootEntityBinding.getEntity().getName(), rootEntityBinding.getDiscriminatorMatchValue() ); + assertEquals( StringHelper.unqualify( rootEntityBinding.getEntity().getName() ), rootEntityBinding.getDiscriminatorMatchValue() ); assertNull( rootEntityBinding.getSuperEntityBinding() ); assertSame( rootEntityBinding, getRootEntityBinding( RootOfSingleTableInheritance.class ) ); assertTrue( rootEntityBinding.isPolymorphic() ); diff --git a/hibernate-core/src/test/java/org/hibernate/sql/TemplateTest.java b/hibernate-core/src/test/java/org/hibernate/sql/TemplateTest.java index 7421f5e554..a15a06dc0a 100644 --- a/hibernate-core/src/test/java/org/hibernate/sql/TemplateTest.java +++ b/hibernate-core/src/test/java/org/hibernate/sql/TemplateTest.java @@ -36,6 +36,7 @@ import org.hibernate.dialect.HSQLDialect; import org.hibernate.dialect.function.SQLFunctionRegistry; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.metamodel.MetadataSources; import org.hibernate.persister.entity.PropertyMapping; import org.hibernate.service.ServiceRegistry; import org.hibernate.sql.ordering.antlr.ColumnMapper; @@ -113,7 +114,13 @@ public static void buildSessionFactory() { Configuration cfg = new Configuration(); cfg.setProperty( AvailableSettings.DIALECT, DIALECT.getClass().getName() ); ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() ); - SESSION_FACTORY = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); + if ( isMetadataUsed ) { + SESSION_FACTORY = (SessionFactoryImplementor) new MetadataSources( serviceRegistry ).buildMetadata() + .buildSessionFactory(); + } + else { + SESSION_FACTORY = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); + } } @AfterClass diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java index 140555fd79..e22dae70f9 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java @@ -45,6 +45,8 @@ import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; +import org.hibernate.metamodel.MetadataSources; +import org.hibernate.service.ServiceRegistry; import org.hibernate.testing.DialectChecks; import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.RequiresDialectFeature; @@ -101,7 +103,6 @@ public void testEntity() throws Exception { @Test @RequiresDialectFeature( DialectChecks.SupportsExpectedLobUsagePattern.class ) - @FailureExpectedWithNewMetamodel public void testVersioning() throws Exception { Forest forest = new Forest(); forest.setName( "Fontainebleau" ); @@ -328,7 +329,6 @@ public void testFilterOnCollection() { } @Test - @FailureExpectedWithNewMetamodel public void testCascadedDeleteOfChildEntitiesBug2() { // Relationship is one SoccerTeam to many Players. // Create a SoccerTeam (parent) and three Players (child). @@ -379,7 +379,6 @@ public void testCascadedDeleteOfChildEntitiesBug2() { } @Test - @FailureExpectedWithNewMetamodel public void testCascadedDeleteOfChildOneToOne() { // create two single player teams (for one versus one match of soccer) // and associate teams with players via the special OneVOne methods. @@ -454,7 +453,7 @@ public void testFilter() throws Exception { assertEquals( 1, count ); s.disableFilter( "betweenLength" ); s.enableFilter( "minLength" ).setParameter( "minLength", 5 ); - count = ( (Long) s.createQuery( "select count(*) from Forest" ).iterate().next() ).longValue(); + count = (Long) s.createQuery( "select count(*) from Forest" ).iterate().next(); assertEquals( 2l, count ); s.disableFilter( "minLength" ); tx.rollback(); @@ -466,7 +465,6 @@ public void testFilter() throws Exception { * defined on a parent MappedSuperclass(s) */ @Test - @FailureExpectedWithNewMetamodel public void testInheritFiltersFromMappedSuperclass() throws Exception { Session s; Transaction tx; @@ -500,9 +498,9 @@ public void testInheritFiltersFromMappedSuperclass() throws Exception { s.disableFilter( "byName" ); s.enableFilter( "byCategory" ).setParameter( "category", "Industrial" ); - count = ( (Long) s.createQuery( "select count(*) from Drill" ).iterate().next() ).longValue(); + count = (Long) s.createQuery( "select count(*) from Drill" ).iterate().next(); assertEquals( 1, count ); - count = ( (Long) s.createQuery( "select count(*) from PowerDrill" ).iterate().next() ).longValue(); + count = (Long) s.createQuery( "select count(*) from PowerDrill" ).iterate().next(); assertEquals( 1, count ); s.disableFilter( "byCategory" ); @@ -655,10 +653,19 @@ public void testTypeDefNameAndDefaultForTypeAttributes() { @Test public void testTypeDefWithoutNameAndDefaultForTypeAttributes() { SessionFactory sf=null; + ServiceRegistry serviceRegistry= null; try { Configuration config = new Configuration(); - config.addAnnotatedClass(LocalContactDetails.class); - sf = config.buildSessionFactory( ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() ) ); + serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() ); + if ( isMetadataUsed ) { + MetadataSources metadataSources = new MetadataSources( serviceRegistry ); + metadataSources.addAnnotatedClass( LocalContactDetails.class ).buildMetadata(); + } + else { + config.addAnnotatedClass( LocalContactDetails.class ); + sf = config.buildSessionFactory( serviceRegistry ); + } + fail("Did not throw expected exception"); } catch( AnnotationException ex ) { @@ -669,6 +676,9 @@ public void testTypeDefWithoutNameAndDefaultForTypeAttributes() { if( sf != null){ sf.close(); } + if( serviceRegistry != null ){ + ServiceRegistryBuilder.destroy( serviceRegistry ); + } } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/HibernateAnnotationMappingTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/HibernateAnnotationMappingTest.java index ef64c9a004..a18f29c41a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/HibernateAnnotationMappingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/HibernateAnnotationMappingTest.java @@ -30,6 +30,9 @@ import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; +import org.hibernate.metamodel.MetadataSources; +import org.hibernate.service.ServiceRegistry; +import org.hibernate.testing.ServiceRegistryBuilder; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; @@ -39,20 +42,37 @@ * @author Guenther Demetz */ public class HibernateAnnotationMappingTest extends BaseUnitTestCase { - + @Test - @TestForIssue( jiraKey = "HHH-7446" ) + @TestForIssue(jiraKey = "HHH-7446") public void testUniqueConstraintAnnotationOnNaturalIds() throws Exception { Configuration configuration = new Configuration(); configuration.setProperty( Environment.HBM2DDL_AUTO, "create-drop" ); - configuration.addAnnotatedClass(Month.class); + ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( configuration.getProperties() ); SessionFactory sf = null; try { - sf = configuration.buildSessionFactory(); - sf.close(); + if ( isMetadataUsed ) { + MetadataSources metadataSources = new MetadataSources( serviceRegistry ); + sf = metadataSources.addAnnotatedClass( Month.class ).buildMetadata().buildSessionFactory(); + + } + else { + configuration.addAnnotatedClass( Month.class ); + sf = configuration.buildSessionFactory(); + + } } - catch (ConcurrentModificationException e) { - fail(e.toString()); + catch ( ConcurrentModificationException e ) { + fail( e.toString() ); } + finally { + if( sf != null ){ + sf.close(); + } + if( serviceRegistry != null ){ + ServiceRegistryBuilder.destroy( serviceRegistry ); + } + } + } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/mixed/Document.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/mixed/Document.java index 70402be518..2fb3c5b04e 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/mixed/Document.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/mixed/Document.java @@ -11,7 +11,7 @@ */ @Entity @DiscriminatorValue("D") -@SecondaryTable(name = "DocumentMixed") +@SecondaryTable(name = "DocumentSecondaryTable") @Table(name="Document_Wrong") //illegal use, a warn is raised public class Document extends File { private int size; @@ -24,7 +24,7 @@ public class Document extends File { this.size = size; } - @Column(table = "DocumentMixed", name="doc_size", nullable = false) + @Column(table = "DocumentSecondaryTable", name="doc_size", nullable = false) public int getSize() { return size; } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/mixed/File.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/mixed/File.java index dc22519817..9ab902873a 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/mixed/File.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/mixed/File.java @@ -15,8 +15,8 @@ */ @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@Table(name = "FileMixed") -@SecondaryTable(name = "FileFolderMixed") +@Table(name = "File") +@SecondaryTable(name = "FileSecondaryTable") @DiscriminatorColumn(length = 1) public abstract class File { private String name; @@ -39,7 +39,7 @@ public void setName(String id) { } @ManyToOne - @JoinColumn(table = "FileFolderMixed") + @JoinColumn(table = "FileSecondaryTable") public Folder getParent() { return parent; } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/mixed/SubclassTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/mixed/SubclassTest.java index 9030f0253d..fa47002bfa 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/mixed/SubclassTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/mixed/SubclassTest.java @@ -30,7 +30,6 @@ import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.exception.SQLGrammarException; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import static org.junit.Assert.assertEquals; @@ -42,7 +41,6 @@ /** * @author Emmanuel Bernard */ -@FailureExpectedWithNewMetamodel public class SubclassTest extends BaseCoreFunctionalTestCase { @Test public void testDefault() throws Exception { diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/mixed/SymbolicLink.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/mixed/SymbolicLink.java index f8be60e9d7..576d6731de 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/mixed/SymbolicLink.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/mixed/SymbolicLink.java @@ -8,7 +8,7 @@ @Entity @DiscriminatorValue("L") -@SecondaryTable(name = "SymbolicLinkMixed") +@SecondaryTable(name = "SymbolicLinkSecondaryTable") public class SymbolicLink extends File { File target; @@ -21,7 +21,7 @@ public SymbolicLink(File target) { } @ManyToOne(optional = false) - @JoinColumn(table = "SymbolicLinkMixed") + @JoinColumn(table = "SymbolicLinkSecondaryTable") public File getTarget() { return target; } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/join/Cat.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/join/Cat.java index d9222787b0..858553a7ab 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/join/Cat.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/join/Cat.java @@ -24,9 +24,13 @@ @SecondaryTable(name = "`Cat nbr1`"), @SecondaryTable(name = "Cat2", uniqueConstraints = {@UniqueConstraint(columnNames = {"storyPart2"})}) }) + + + @Tables( { @Table(appliesTo = "Cat", indexes = @Index(name = "secondname", columnNames = "secondName"), comment = "My cat table" ), + @Table(appliesTo = "Cat2", foreignKey = @ForeignKey(name="FK_CAT2_CAT"), fetch = FetchMode.SELECT, sqlInsert=@SQLInsert(sql="insert into Cat2(storyPart2, id) values(upper(?), ?)") ) } ) diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/join/JoinTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/join/JoinTest.java index 9c9abbe0bd..c1bde2e1e9 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/join/JoinTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/join/JoinTest.java @@ -44,7 +44,6 @@ import org.hibernate.metamodel.spi.relational.Table; import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.test.util.SchemaUtil; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; @@ -53,7 +52,6 @@ */ public class JoinTest extends BaseCoreFunctionalTestCase { @Test -// @FailureExpectedWithNewMetamodel public void testDefaultValue() throws Exception { TableSpecification joinTable = SchemaUtil.getEntityBinding( Life.class, metadata() ).locateTable( "ExtendedLife" ); assertNotNull( joinTable ); @@ -77,7 +75,6 @@ public void testDefaultValue() throws Exception { } @Test -// @FailureExpectedWithNewMetamodel public void testCompositePK() throws Exception { if ( isMetadataUsed() ) { SecondaryTable secondaryTable = @@ -144,7 +141,6 @@ public void testExplicitValue() throws Exception { } @Test - @FailureExpectedWithNewMetamodel( message = "sequential selects not supported yet.") public void testManyToOne() throws Exception { Session s = openSession(); Transaction tx = s.beginTransaction(); @@ -209,7 +205,6 @@ public void testUniqueConstaintOnSecondaryTable() throws Exception { } @Test - @FailureExpectedWithNewMetamodel public void testFetchModeOnSecondaryTable() throws Exception { Cat cat = new Cat(); cat.setStoryPart2( "My long story" ); @@ -228,7 +223,6 @@ public void testFetchModeOnSecondaryTable() throws Exception { } @Test - @FailureExpectedWithNewMetamodel public void testCustomSQL() throws Exception { Cat cat = new Cat(); String storyPart2 = "My long story"; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/uniqueconstraint/UniqueConstraintValidationTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/uniqueconstraint/UniqueConstraintValidationTest.java index 788c130427..2c58b26f65 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/uniqueconstraint/UniqueConstraintValidationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/uniqueconstraint/UniqueConstraintValidationTest.java @@ -9,9 +9,12 @@ import org.junit.Test; import org.hibernate.AnnotationException; +import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.Configuration; +import org.hibernate.metamodel.MetadataSources; import org.hibernate.service.spi.ServiceRegistryImplementor; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; @@ -23,6 +26,7 @@ public class UniqueConstraintValidationTest extends BaseUnitTestCase { @Test(expected = AnnotationException.class) @TestForIssue(jiraKey = "HHH-4084") + @FailureExpectedWithNewMetamodel public void testUniqueConstraintWithEmptyColumnName() { buildSessionFactory(EmptyColumnNameEntity.class); } @@ -33,18 +37,28 @@ public void testUniqueConstraintWithEmptyColumnNameList() { } @Test(expected = AnnotationException.class) + @FailureExpectedWithNewMetamodel public void testUniqueConstraintWithNotExistsColumnName() { buildSessionFactory(NotExistsColumnEntity.class); } private void buildSessionFactory(Class entity) { - Configuration cfg = new Configuration(); - cfg.addAnnotatedClass(entity); - cfg.buildMappings(); - ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder() - .applySettings(cfg.getProperties()).build(); - cfg.buildSessionFactory(serviceRegistry).close(); - serviceRegistry.destroy(); + if ( isMetadataUsed ) { + StandardServiceRegistry registry = new StandardServiceRegistryBuilder().build(); + MetadataSources metadataSources = new MetadataSources( registry ); + metadataSources.addAnnotatedClass( entity ); + metadataSources.buildMetadata(); + StandardServiceRegistryBuilder.destroy( registry ); + } + else { + Configuration cfg = new Configuration(); + cfg.addAnnotatedClass( entity ); + cfg.buildMappings(); + ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder() + .applySettings( cfg.getProperties() ).build(); + cfg.buildSessionFactory( serviceRegistry ).close(); + serviceRegistry.destroy(); + } } @Entity diff --git a/hibernate-core/src/test/java/org/hibernate/test/extralazy/ExtraLazyTest.java b/hibernate-core/src/test/java/org/hibernate/test/extralazy/ExtraLazyTest.java index 3c3b5de898..c642880b42 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/extralazy/ExtraLazyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/extralazy/ExtraLazyTest.java @@ -42,7 +42,6 @@ /** * @author Gavin King */ -//@FailureExpectedWithNewMetamodel public class ExtraLazyTest extends BaseCoreFunctionalTestCase { @Override public String[] getMappings() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/table/BasicTableTest.java b/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/table/BasicTableTest.java index 347d19454c..3fe0f8350b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/table/BasicTableTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/table/BasicTableTest.java @@ -28,7 +28,6 @@ import org.hibernate.Session; import org.hibernate.id.enhanced.TableGenerator; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder; @@ -38,7 +37,6 @@ /** * @author Steve Ebersole */ -@FailureExpectedWithNewMetamodel public class BasicTableTest extends BaseCoreFunctionalTestCase { @Override public String[] getMappings() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/table/HiLoTableTest.java b/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/table/HiLoTableTest.java index 9f9fb53a62..a540971d50 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/table/HiLoTableTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/table/HiLoTableTest.java @@ -29,7 +29,6 @@ import org.hibernate.id.enhanced.OptimizerFactory; import org.hibernate.id.enhanced.TableGenerator; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder; @@ -39,7 +38,6 @@ /** * @author Steve Ebersole */ -@FailureExpectedWithNewMetamodel public class HiLoTableTest extends BaseCoreFunctionalTestCase { @Override public String[] getMappings() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/ABCTest.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/ABCTest.java index 0c0c4385d8..0726a36119 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/ABCTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/ABCTest.java @@ -29,12 +29,16 @@ import org.hibernate.Session; import org.hibernate.Transaction; +import org.hibernate.metamodel.spi.relational.Index; +import org.hibernate.metamodel.spi.relational.Schema; +import org.hibernate.metamodel.spi.relational.Table; import org.hibernate.testing.FailureExpectedWithNewMetamodel; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; @SuppressWarnings( {"UnnecessaryBoxing"}) public class ABCTest extends LegacyTestCase { @@ -79,16 +83,16 @@ public void testFormulaAssociation() throws Throwable { @Test @FailureExpectedWithNewMetamodel public void testHigherLevelIndexDefinition() throws Throwable { - String[] commands = configuration().generateSchemaCreationScript( getDialect() ); - int max = commands.length; - boolean found = false; - for (int indx = 0; indx < max; indx++) { - System.out.println("Checking command : " + commands[indx]); - found = commands[indx].indexOf("create index indx_a_name") >= 0; - if (found) - break; + for ( Schema schema : metadata().getDatabase().getSchemas() ) { + for ( Table table : schema.getTables() ) { + for ( Index index : table.getIndexes() ) { + if ( index.getName().equals( "indx_a_name" ) ) { + return; + } + } + } } - assertTrue("Unable to locate indx_a_name index creation", found); + fail( "Unable to locate indx_a_name index creation" ); } @Test diff --git a/hibernate-core/src/test/java/org/hibernate/test/map/MapIndexFormulaTest.java b/hibernate-core/src/test/java/org/hibernate/test/map/MapIndexFormulaTest.java index 5758e959e1..1da9c5235d 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/map/MapIndexFormulaTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/map/MapIndexFormulaTest.java @@ -37,7 +37,7 @@ /** * @author Gavin King */ -@FailureExpectedWithNewMetamodel + public class MapIndexFormulaTest extends BaseCoreFunctionalTestCase { @Override public String[] getMappings() { @@ -59,6 +59,7 @@ public void testIndexFunctionOnManyToManyMap() { } @Test + @FailureExpectedWithNewMetamodel @SuppressWarnings( {"unchecked", "UnnecessaryBoxing"}) public void testIndexFormulaMap() { Session s = openSession(); @@ -113,6 +114,7 @@ public void testIndexFormulaMap() { } @Test + @FailureExpectedWithNewMetamodel @SuppressWarnings( {"unchecked"}) public void testSQLQuery() { Session s = openSession(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/mapping/ValueVisitorTest.java b/hibernate-core/src/test/java/org/hibernate/test/mapping/ValueVisitorTest.java index 872d393c81..cd4ca48ced 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/mapping/ValueVisitorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/mapping/ValueVisitorTest.java @@ -52,6 +52,10 @@ public class ValueVisitorTest extends BaseUnitTestCase { @Test public void testProperCallbacks() { + if ( isMetadataUsed ) { + //doesn't mean anything for new metamodel + return; + } final Mappings mappings = new Configuration().createMappings(); final Table tbl = new Table(); final RootClass rootClass = new RootClass(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/mapping/usertypes/UserTypeMappingTest.java b/hibernate-core/src/test/java/org/hibernate/test/mapping/usertypes/UserTypeMappingTest.java index 2f1216cfc3..4f7760a887 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/mapping/usertypes/UserTypeMappingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/mapping/usertypes/UserTypeMappingTest.java @@ -10,6 +10,7 @@ import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; +import org.hibernate.metamodel.MetadataSources; import org.hibernate.service.ServiceRegistry; import org.hibernate.testing.ServiceRegistryBuilder; import org.hibernate.testing.TestForIssue; @@ -18,50 +19,63 @@ /** * Test for read-order independent resolution of user-defined types * Testcase for issue HHH-7300 + * * @author Stefan Schulze */ @TestForIssue(jiraKey = "HHH-7300") -public class UserTypeMappingTest extends BaseUnitTestCase{ +public class UserTypeMappingTest extends BaseUnitTestCase { -private Configuration cfg; -private ServiceRegistry serviceRegistry; + @Test + public void testFirstTypeThenEntity() { + assertMappings( + "org/hibernate/test/mapping/usertypes/TestEnumType.hbm.xml", + "org/hibernate/test/mapping/usertypes/TestEntity.hbm.xml" + ); + } - @Before - public void setup(){ - cfg=new Configuration(); + @Test + public void testFirstEntityThenType() { + assertMappings( + "org/hibernate/test/mapping/usertypes/TestEntity.hbm.xml", + "org/hibernate/test/mapping/usertypes/TestEnumType.hbm.xml" + ); + } + + private void assertMappings(String... mappings) { + Configuration cfg = new Configuration(); Properties p = new Properties(); p.put( Environment.DIALECT, "org.hibernate.dialect.HSQLDialect" ); p.put( "hibernate.connection.driver_class", "org.h2.Driver" ); p.put( "hibernate.connection.url", "jdbc:h2:mem:" ); p.put( "hibernate.connection.username", "sa" ); p.put( "hibernate.connection.password", "" ); - cfg.setProperties(p); - serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() ); - } - - public void tearDown(){ - if(serviceRegistry!=null){ - ServiceRegistryBuilder.destroy( serviceRegistry ); + cfg.setProperties( p ); + ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() ); + SessionFactory sessions = null; + try { + if ( isMetadataUsed ) { + MetadataSources metadataSources = new MetadataSources( serviceRegistry ); + for ( String mapping : mappings ) { + metadataSources.addResource( mapping ); + } + sessions = metadataSources.buildMetadata().buildSessionFactory(); + } + else { + for ( String mapping : mappings ) { + cfg.addResource( mapping ); + } + sessions = cfg.buildSessionFactory( serviceRegistry ); + } + Assert.assertNotNull( sessions ); + } + finally { + if ( sessions != null ) { + sessions.close(); + } + if ( serviceRegistry != null ) { + ServiceRegistryBuilder.destroy( serviceRegistry ); + } } - } - - @Test - public void testFirstTypeThenEntity(){ - cfg.addResource("org/hibernate/test/mapping/usertypes/TestEnumType.hbm.xml") - .addResource("org/hibernate/test/mapping/usertypes/TestEntity.hbm.xml"); - SessionFactory sessions=cfg.buildSessionFactory(serviceRegistry); - Assert.assertNotNull(sessions); - sessions.close(); - } - - @Test - public void testFirstEntityThenType(){ - cfg.addResource("org/hibernate/test/mapping/usertypes/TestEntity.hbm.xml") - .addResource("org/hibernate/test/mapping/usertypes/TestEnumType.hbm.xml"); - - SessionFactory sessions=cfg.buildSessionFactory(serviceRegistry); - Assert.assertNotNull(sessions); - sessions.close(); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/propertyref/basic/PropertyRefTest.java b/hibernate-core/src/test/java/org/hibernate/test/propertyref/basic/PropertyRefTest.java index 99e04803cf..786c6e68f8 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/propertyref/basic/PropertyRefTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/propertyref/basic/PropertyRefTest.java @@ -35,8 +35,9 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.ForeignKey; +import org.hibernate.metamodel.spi.binding.EntityBinding; +import org.hibernate.metamodel.spi.relational.Column; +import org.hibernate.metamodel.spi.relational.ForeignKey; import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.test.util.SchemaUtil; import org.hibernate.testing.FailureExpectedWithNewMetamodel; @@ -52,7 +53,6 @@ /** * @author Gavin King */ -@FailureExpectedWithNewMetamodel public class PropertyRefTest extends BaseCoreFunctionalTestCase { @Override public String[] getMappings() { @@ -111,6 +111,7 @@ public void testNonLazyBagKeyPropertyRef() { } @Test + @FailureExpectedWithNewMetamodel public void testManyToManyPropertyRef() { // prepare some test data relating to the Group->Person many-to-many association Session s = openSession(); @@ -281,25 +282,25 @@ public void testJoinFetchPropertyRef() { @Test public void testForeignKeyCreation() { + if ( !isMetadataUsed ) { + return; + } TableSpecification table = SchemaUtil.getTable( Account.class, metadata() ); - + EntityBinding personEntityBinding = getEntityBinding( Person.class ); Iterator foreignKeyIterator = table.getForeignKeys().iterator(); boolean found = false; while ( foreignKeyIterator.hasNext() ) { ForeignKey element = (ForeignKey) foreignKeyIterator.next(); - if(element.getReferencedEntityName().equals(Person.class.getName() ) ) { - - if(!element.isReferenceToPrimaryKey() ) { - List referencedColumns = element.getReferencedColumns(); - Column column = (Column) referencedColumns.get(0); - if(column.getName().equals("person_userid") ) { - found = true; // extend test to include the columns + if ( element.getTargetTable().equals( personEntityBinding.getPrimaryTable() ) ) { + for ( Column column : element.getTargetColumns() ) { + if ( column.getColumnName().getText( getDialect() ).equals( "person_userid" ) ) { + found = true; } } } } - assertTrue("Property ref foreign key not found",found); + assertTrue( "Property ref foreign key not found", found ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/subselect/SubselectTest.java b/hibernate-core/src/test/java/org/hibernate/test/subselect/SubselectTest.java index aa897b2ddc..017b4b398a 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/subselect/SubselectTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/subselect/SubselectTest.java @@ -30,7 +30,6 @@ import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.criterion.Restrictions; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import static org.junit.Assert.assertEquals; @@ -48,7 +47,6 @@ public String[] getMappings() { @Test @SuppressWarnings( {"unchecked"}) - @FailureExpectedWithNewMetamodel public void testEntitySubselect() { Session s = openSession(); Transaction t = s.beginTransaction(); @@ -89,7 +87,6 @@ public void testEntitySubselect() { } @Test - @FailureExpectedWithNewMetamodel public void testCustomColumnReadAndWrite() { Session s = openSession(); Transaction t = s.beginTransaction(); diff --git a/hibernate-core/src/test/resources/org/hibernate/test/propertyref/basic/Person.hbm.xml b/hibernate-core/src/test/resources/org/hibernate/test/propertyref/basic/Person.hbm.xml index e5f75d9a80..867b4b170f 100644 --- a/hibernate-core/src/test/resources/org/hibernate/test/propertyref/basic/Person.hbm.xml +++ b/hibernate-core/src/test/resources/org/hibernate/test/propertyref/basic/Person.hbm.xml @@ -22,7 +22,7 @@ - + @@ -39,7 +39,7 @@ - + diff --git a/hibernate-core/src/test/resources/org/hibernate/test/subselect/Beings.hbm.xml b/hibernate-core/src/test/resources/org/hibernate/test/subselect/Beings.hbm.xml index adc3ebc2a7..3869345078 100755 --- a/hibernate-core/src/test/resources/org/hibernate/test/subselect/Beings.hbm.xml +++ b/hibernate-core/src/test/resources/org/hibernate/test/subselect/Beings.hbm.xml @@ -27,7 +27,7 @@ - + - + [] NO_CLASSES = new Class[0]; protected Configuration configuration; protected MetadataImplementor metadata; protected StandardServiceRegistryImpl serviceRegistry; - protected boolean isMetadataUsed; + protected static Dialect getDialect() { return DIALECT; @@ -50,9 +50,7 @@ protected MetadataImplementor metadata() { return metadata; } - protected boolean isMetadataUsed() { - return isMetadataUsed; - } + //----------------------- services and service registry protected BootstrapServiceRegistry buildBootstrapServiceRegistry() { diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java index 4015017a38..7b348e8f52 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java @@ -34,6 +34,7 @@ import org.hibernate.engine.jdbc.spi.SqlStatementLogger; import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper; +import org.hibernate.metamodel.MetadataSources; import org.hibernate.testing.jta.TestingJtaPlatformImpl; /** @@ -44,15 +45,18 @@ @RunWith( CustomRunner.class ) public abstract class BaseUnitTestCase { private static final Logger log = Logger.getLogger( BaseUnitTestCase.class ); - + public static final String USE_NEW_METADATA_MAPPINGS = MetadataSources.USE_NEW_METADATA_MAPPINGS; /** * String that should be prepended to all standard output placed in tests. Output without this prefix may cause test * subclasses of {@link BaseSqlOutputTest} to fail. */ protected static final String OUTPUT_PREFIX = SqlStatementLogger.OUTPUT_PREFIX; - -// @Rule -// public TestRule globalTimeout = new Timeout( 30 * 60 * 1000 ); // no test should run longer than 30 minutes + protected static boolean isMetadataUsed = Boolean.valueOf( System.getProperty( USE_NEW_METADATA_MAPPINGS, "true" ) ); + protected static boolean isMetadataUsed() { + return isMetadataUsed; + } + @Rule + public TestRule globalTimeout = new Timeout( 30 * 60 * 1000 ); // no test should run longer than 30 minutes @After public void releaseTransactions() {