HHH-7919 : Miscellaneous bugfixes
This commit is contained in:
parent
fe6d6770d8
commit
2ad468ea73
|
@ -1638,7 +1638,7 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
|
|||
int size = implementors.length;
|
||||
|
||||
CriteriaLoader[] loaders = new CriteriaLoader[size];
|
||||
Set spaces = new HashSet();
|
||||
Set<Serializable> spaces = new HashSet<Serializable>();
|
||||
for( int i=0; i <size; i++ ) {
|
||||
|
||||
loaders[i] = new CriteriaLoader(
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
*
|
||||
*/
|
||||
package org.hibernate.loader.criteria;
|
||||
import java.io.Serializable;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
|
@ -68,7 +69,7 @@ public class CriteriaLoader extends OuterJoinLoader {
|
|||
// multithreaded, or cacheable!!
|
||||
|
||||
private final CriteriaQueryTranslator translator;
|
||||
private final Set querySpaces;
|
||||
private final Set<Serializable> 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 @@ public class CriteriaLoader extends OuterJoinLoader {
|
|||
}
|
||||
}
|
||||
|
||||
public Set getQuerySpaces() {
|
||||
public Set<Serializable> getQuerySpaces() {
|
||||
return querySpaces;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,9 @@ import org.hibernate.metamodel.spi.binding.EntityBinding;
|
|||
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<BasicType> getBasicTypeRegistrations();
|
||||
MetadataSourceProcessingOrder getMetadataSourceProcessingOrder();
|
||||
NamingStrategy getNamingStrategy();
|
||||
EntityResolver getEntityResolver();
|
||||
SharedCacheMode getSharedCacheMode();
|
||||
AccessType getDefaultAccessType();
|
||||
boolean useNewIdentifierGenerators();
|
||||
boolean isGloballyQuotedIdentifiers();
|
||||
String getDefaultSchemaName();
|
||||
String getDefaultCatalogName();
|
||||
MultiTenancyStrategy getMultiTenancyStrategy();
|
||||
IndexView getJandexView();
|
||||
List<BasicType> getBasicTypeRegistrations();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,14 +78,14 @@ public interface Metadata {
|
|||
*
|
||||
* @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 interface Metadata {
|
|||
*
|
||||
* @return THe built SessionFactory.
|
||||
*/
|
||||
public SessionFactory buildSessionFactory();
|
||||
SessionFactory buildSessionFactory();
|
||||
|
||||
public Iterable<EntityBinding> 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<PluralAttributeBinding> getCollectionBindings();
|
||||
Iterable<PluralAttributeBinding> getCollectionBindings();
|
||||
Iterable<EntityBinding> getEntityBindings();
|
||||
Iterable<TypeDefinition> getTypeDefinitions();
|
||||
Iterable<NamedQueryDefinition> getNamedQueryDefinitions();
|
||||
Iterable<NamedSQLQueryDefinition> getNamedNativeQueryDefinitions();
|
||||
Iterable<FetchProfile> getFetchProfiles();
|
||||
|
||||
public boolean hasTypeDefinition(String name);
|
||||
|
||||
public TypeDefinition getTypeDefinition(String name);
|
||||
|
||||
public Iterable<TypeDefinition> getTypeDefinitions();
|
||||
|
||||
public Map<String, FilterDefinition> getFilterDefinitions();
|
||||
|
||||
public Iterable<NamedQueryDefinition> getNamedQueryDefinitions();
|
||||
|
||||
public Map<String, NamedEntityGraphDefinition> getNamedEntityGraphMap();
|
||||
|
||||
public Iterable<NamedSQLQueryDefinition> getNamedNativeQueryDefinitions();
|
||||
|
||||
public Map<String, ResultSetMappingDefinition> getResultSetMappingDefinitions();
|
||||
|
||||
public Map<String,String> getImports();
|
||||
|
||||
public Iterable<FetchProfile> getFetchProfiles();
|
||||
|
||||
public IdGenerator getIdGenerator(String name);
|
||||
Map<Identifier, SecondaryTable> getSecondaryTables();
|
||||
Map<String, FilterDefinition> getFilterDefinitions();
|
||||
Map<String, NamedEntityGraphDefinition> getNamedEntityGraphs();
|
||||
Map<String, ResultSetMappingDefinition> getResultSetMappingDefinitions();
|
||||
Map<String,String> getImports();
|
||||
}
|
||||
|
|
|
@ -781,13 +781,16 @@ public class Binder {
|
|||
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 @@ public class Binder {
|
|||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -87,11 +87,13 @@ import org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding;
|
|||
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<String, TypeDefinition> typeDefinitionMap = new HashMap<String, TypeDefinition>();
|
||||
private Map<String, FilterDefinition> filterDefinitionMap = new HashMap<String, FilterDefinition>();
|
||||
private final Map<String, FilterDefinition> filterDefinitionMap = new HashMap<String, FilterDefinition>();
|
||||
|
||||
private Map<String, EntityBinding> entityBindingMap = new HashMap<String, EntityBinding>();
|
||||
private Map<String, PluralAttributeBinding> collectionBindingMap = new HashMap<String, PluralAttributeBinding>();
|
||||
private Map<String, FetchProfile> fetchProfiles = new HashMap<String, FetchProfile>();
|
||||
private Map<String, String> imports = new HashMap<String, String>();
|
||||
private Map<String, IdGenerator> idGenerators = new HashMap<String, IdGenerator>();
|
||||
private Map<String, NamedQueryDefinition> namedQueryDefs = new HashMap<String, NamedQueryDefinition>();
|
||||
private Map<String, NamedSQLQueryDefinition> namedNativeQueryDefs = new HashMap<String, NamedSQLQueryDefinition>();
|
||||
private Map<String, ResultSetMappingDefinition> resultSetMappings = new HashMap<String, ResultSetMappingDefinition>();
|
||||
private final Map<String, EntityBinding> entityBindingMap = new HashMap<String, EntityBinding>();
|
||||
private final Map<String, PluralAttributeBinding> collectionBindingMap = new HashMap<String, PluralAttributeBinding>();
|
||||
private final Map<String, FetchProfile> fetchProfiles = new HashMap<String, FetchProfile>();
|
||||
private final Map<String, String> imports = new HashMap<String, String>();
|
||||
private final Map<String, IdGenerator> idGenerators = new HashMap<String, IdGenerator>();
|
||||
private final Map<String, NamedQueryDefinition> namedQueryDefs = new HashMap<String, NamedQueryDefinition>();
|
||||
private final Map<String, NamedSQLQueryDefinition> namedNativeQueryDefs = new HashMap<String, NamedSQLQueryDefinition>();
|
||||
private final Map<String, ResultSetMappingDefinition> resultSetMappings = new HashMap<String, ResultSetMappingDefinition>();
|
||||
private final Map<String, NamedEntityGraphDefinition> namedEntityGraphMap = new HashMap<String, NamedEntityGraphDefinition>( );
|
||||
private final Map<Identifier, SecondaryTable> secondaryTableMap = new HashMap<Identifier, SecondaryTable>( );
|
||||
|
||||
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 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
};
|
||||
}
|
||||
|
||||
this.classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
|
||||
// this.persisterClassResolverService = new ValueHolder<PersisterClassResolver>(
|
||||
// new ValueHolder.DeferredInitializer<PersisterClassResolver>() {
|
||||
// @Override
|
||||
|
@ -387,7 +390,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<String, NamedEntityGraphDefinition> getNamedEntityGraphMap() {
|
||||
public Map<String, NamedEntityGraphDefinition> getNamedEntityGraphs() {
|
||||
return namedEntityGraphMap;
|
||||
}
|
||||
|
||||
|
@ -728,6 +731,16 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSecondaryTable(SecondaryTable secondaryTable) {
|
||||
secondaryTableMap.put( secondaryTable.getSecondaryTableReference().getLogicalName(), secondaryTable );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Identifier, SecondaryTable> getSecondaryTables() {
|
||||
return secondaryTableMap;
|
||||
}
|
||||
|
||||
public PluralAttributeBinding getCollection(String collectionRole) {
|
||||
return collectionBindingMap.get( collectionRole );
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.util.List;
|
|||
|
||||
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 class SecondaryTableSourceImpl implements SecondaryTableSource {
|
|||
|
||||
@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
|
||||
|
|
|
@ -29,12 +29,17 @@ import org.jboss.jandex.AnnotationInstance;
|
|||
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 @@ public class TableProcessor {
|
|||
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 @@ public class TableProcessor {
|
|||
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() );
|
||||
|
|
|
@ -61,7 +61,7 @@ public class AnnotationParserHelper {
|
|||
return createCustomSQL( sqlAnnotation );
|
||||
}
|
||||
|
||||
private static CustomSQL createCustomSQL(AnnotationInstance customSqlAnnotation) {
|
||||
public static CustomSQL createCustomSQL(AnnotationInstance customSqlAnnotation) {
|
||||
if ( customSqlAnnotation == null ) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ import javax.persistence.GeneratedValue;
|
|||
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() );
|
||||
|
|
|
@ -100,8 +100,7 @@ abstract class AbstractMocker implements JPADotNames {
|
|||
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
|
||||
MockHelper.stringValue( "name", uniqueConstraint.getName(), annotationValueList );
|
||||
MockHelper.stringArrayValue( "columnNames", uniqueConstraint.getColumnName(), annotationValueList );
|
||||
return
|
||||
create( UNIQUE_CONSTRAINT, target,
|
||||
return create( UNIQUE_CONSTRAINT, target,
|
||||
annotationValueList );
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.hibernate.jaxb.spi.hbm.JaxbColumnElement;
|
|||
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 @@ class SecondaryTableSourceImpl extends AbstractHbmSourceNode implements Secondar
|
|||
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()
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.hibernate.metamodel.spi.binding.EntityBinding;
|
|||
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);
|
||||
|
|
|
@ -804,8 +804,7 @@ public class EntityBinding extends AbstractAttributeBindingContainer implements
|
|||
}
|
||||
|
||||
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 ) );
|
||||
}
|
||||
|
||||
|
|
|
@ -33,10 +33,13 @@ import org.hibernate.metamodel.spi.relational.TableSpecification;
|
|||
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 class SecondaryTable {
|
|||
// 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,4 +32,5 @@ public interface LocalBindingContext extends BindingContext {
|
|||
public Origin getOrigin();
|
||||
public MappingException makeMappingException(String message);
|
||||
public MappingException makeMappingException(String message, Exception cause);
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ package org.hibernate.metamodel.spi.source;
|
|||
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();
|
||||
}
|
||||
|
|
|
@ -3800,21 +3800,25 @@ public abstract class AbstractEntityPersister
|
|||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -267,8 +267,9 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
|||
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 class SingleTableEntityPersister extends AbstractEntityPersister {
|
|||
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<org.hibernate.metamodel.spi.relational.Column> joinColumns = join.getForeignKeyReference().getSourceColumns();
|
||||
keyColumnNames[j] = new String[ joinColumns.size() ];
|
||||
|
@ -566,9 +567,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
|||
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<org.hibernate.metamodel.spi.relational.Column> joinColumns = join.getForeignKeyReference().getSourceColumns();
|
||||
String[] keyCols = new String[ joinColumns.size() ];
|
||||
|
@ -686,15 +685,16 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
|||
ArrayList<Integer> propertyJoinNumbers = new ArrayList<Integer>();
|
||||
|
||||
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 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
|||
}
|
||||
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 class SingleTableEntityPersister extends AbstractEntityPersister {
|
|||
}
|
||||
return qualifiedTableNames[ propertyTableNumbers[ index ] ];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInstantiate() {
|
||||
super.postInstantiate();
|
||||
if (hasSequentialSelects) {
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.junit.Test;
|
|||
|
||||
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 class InheritanceBindingTest extends BaseAnnotationBindingTestCase {
|
|||
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() );
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.hibernate.dialect.Dialect;
|
|||
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,8 +114,14 @@ public class TemplateTest extends BaseUnitTestCase {
|
|||
Configuration cfg = new Configuration();
|
||||
cfg.setProperty( AvailableSettings.DIALECT, DIALECT.getClass().getName() );
|
||||
ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
|
||||
if ( isMetadataUsed ) {
|
||||
SESSION_FACTORY = (SessionFactoryImplementor) new MetadataSources( serviceRegistry ).buildMetadata()
|
||||
.buildSessionFactory();
|
||||
}
|
||||
else {
|
||||
SESSION_FACTORY = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void closeSessionFactory() {
|
||||
|
|
|
@ -45,6 +45,8 @@ import org.hibernate.Session;
|
|||
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 class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
@RequiresDialectFeature( DialectChecks.SupportsExpectedLobUsagePattern.class )
|
||||
@FailureExpectedWithNewMetamodel
|
||||
public void testVersioning() throws Exception {
|
||||
Forest forest = new Forest();
|
||||
forest.setName( "Fontainebleau" );
|
||||
|
@ -328,7 +329,6 @@ public class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@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 class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@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 class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
|
|||
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 class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
|
|||
* defined on a parent MappedSuperclass(s)
|
||||
*/
|
||||
@Test
|
||||
@FailureExpectedWithNewMetamodel
|
||||
public void testInheritFiltersFromMappedSuperclass() throws Exception {
|
||||
Session s;
|
||||
Transaction tx;
|
||||
|
@ -500,9 +498,9 @@ public class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
|
|||
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 class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
|
|||
@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 class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
|
|||
if( sf != null){
|
||||
sf.close();
|
||||
}
|
||||
if( serviceRegistry != null ){
|
||||
ServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,9 @@ import org.junit.Test;
|
|||
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;
|
||||
|
||||
|
@ -41,18 +44,35 @@ import static org.junit.Assert.fail;
|
|||
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 {
|
||||
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() );
|
||||
}
|
||||
finally {
|
||||
if( sf != null ){
|
||||
sf.close();
|
||||
}
|
||||
catch (ConcurrentModificationException e) {
|
||||
fail(e.toString());
|
||||
if( serviceRegistry != null ){
|
||||
ServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import javax.persistence.Table;
|
|||
*/
|
||||
@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;
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ import javax.persistence.Table;
|
|||
*/
|
||||
@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 abstract class File {
|
|||
}
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(table = "FileFolderMixed")
|
||||
@JoinColumn(table = "FileSecondaryTable")
|
||||
public Folder getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.junit.Test;
|
|||
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 @@ import static org.junit.Assert.fail;
|
|||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@FailureExpectedWithNewMetamodel
|
||||
public class SubclassTest extends BaseCoreFunctionalTestCase {
|
||||
@Test
|
||||
public void testDefault() throws Exception {
|
||||
|
|
|
@ -8,7 +8,7 @@ import javax.persistence.SecondaryTable;
|
|||
|
||||
@Entity
|
||||
@DiscriminatorValue("L")
|
||||
@SecondaryTable(name = "SymbolicLinkMixed")
|
||||
@SecondaryTable(name = "SymbolicLinkSecondaryTable")
|
||||
public class SymbolicLink extends File {
|
||||
|
||||
File target;
|
||||
|
@ -21,7 +21,7 @@ public class SymbolicLink extends File {
|
|||
}
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(table = "SymbolicLinkMixed")
|
||||
@JoinColumn(table = "SymbolicLinkSecondaryTable")
|
||||
public File getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
|
|
@ -24,9 +24,13 @@ import org.hibernate.annotations.Tables;
|
|||
@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(?), ?)") )
|
||||
} )
|
||||
|
|
|
@ -44,7 +44,6 @@ import org.hibernate.metamodel.spi.relational.PrimaryKey;
|
|||
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 @@ import org.junit.Test;
|
|||
*/
|
||||
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 class JoinTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
// @FailureExpectedWithNewMetamodel
|
||||
public void testCompositePK() throws Exception {
|
||||
if ( isMetadataUsed() ) {
|
||||
SecondaryTable secondaryTable =
|
||||
|
@ -144,7 +141,6 @@ public class JoinTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@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 class JoinTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
@FailureExpectedWithNewMetamodel
|
||||
public void testFetchModeOnSecondaryTable() throws Exception {
|
||||
Cat cat = new Cat();
|
||||
cat.setStoryPart2( "My long story" );
|
||||
|
@ -228,7 +223,6 @@ public class JoinTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
@FailureExpectedWithNewMetamodel
|
||||
public void testCustomSQL() throws Exception {
|
||||
Cat cat = new Cat();
|
||||
String storyPart2 = "My long story";
|
||||
|
|
|
@ -9,9 +9,12 @@ import javax.persistence.UniqueConstraint;
|
|||
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,19 +37,29 @@ public class UniqueConstraintValidationTest extends BaseUnitTestCase {
|
|||
}
|
||||
|
||||
@Test(expected = AnnotationException.class)
|
||||
@FailureExpectedWithNewMetamodel
|
||||
public void testUniqueConstraintWithNotExistsColumnName() {
|
||||
buildSessionFactory(NotExistsColumnEntity.class);
|
||||
}
|
||||
|
||||
private void buildSessionFactory(Class<?> entity) {
|
||||
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.addAnnotatedClass( entity );
|
||||
cfg.buildMappings();
|
||||
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder()
|
||||
.applySettings(cfg.getProperties()).build();
|
||||
cfg.buildSessionFactory(serviceRegistry).close();
|
||||
.applySettings( cfg.getProperties() ).build();
|
||||
cfg.buildSessionFactory( serviceRegistry ).close();
|
||||
serviceRegistry.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Table(name = "tbl_emptycolumnnameentity", uniqueConstraints = @UniqueConstraint(columnNames = ""))
|
||||
|
|
|
@ -42,7 +42,6 @@ import static org.junit.Assert.assertTrue;
|
|||
/**
|
||||
* @author Gavin King
|
||||
*/
|
||||
//@FailureExpectedWithNewMetamodel
|
||||
public class ExtraLazyTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
|
|
|
@ -28,7 +28,6 @@ import org.junit.Test;
|
|||
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 @@ import static org.junit.Assert.assertEquals;
|
|||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@FailureExpectedWithNewMetamodel
|
||||
public class BasicTableTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.hibernate.Session;
|
|||
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 @@ import static org.junit.Assert.assertEquals;
|
|||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@FailureExpectedWithNewMetamodel
|
||||
public class HiLoTableTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
|
|
|
@ -29,12 +29,16 @@ import org.junit.Test;
|
|||
|
||||
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 class ABCTest extends LegacyTestCase {
|
|||
@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
|
||||
|
|
|
@ -37,7 +37,7 @@ import static org.junit.Assert.assertEquals;
|
|||
/**
|
||||
* @author Gavin King
|
||||
*/
|
||||
@FailureExpectedWithNewMetamodel
|
||||
|
||||
public class MapIndexFormulaTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
|
@ -59,6 +59,7 @@ public class MapIndexFormulaTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
@FailureExpectedWithNewMetamodel
|
||||
@SuppressWarnings( {"unchecked", "UnnecessaryBoxing"})
|
||||
public void testIndexFormulaMap() {
|
||||
Session s = openSession();
|
||||
|
@ -113,6 +114,7 @@ public class MapIndexFormulaTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
@FailureExpectedWithNewMetamodel
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public void testSQLQuery() {
|
||||
Session s = openSession();
|
||||
|
|
|
@ -52,6 +52,10 @@ import org.hibernate.testing.junit4.BaseUnitTestCase;
|
|||
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();
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.junit.Test;
|
|||
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 @@ import org.hibernate.testing.junit4.BaseUnitTestCase;
|
|||
/**
|
||||
* 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() );
|
||||
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 );
|
||||
}
|
||||
|
||||
public void tearDown(){
|
||||
if(serviceRegistry!=null){
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,8 +35,9 @@ import org.hibernate.Transaction;
|
|||
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 @@ import static org.junit.Assert.assertTrue;
|
|||
/**
|
||||
* @author Gavin King
|
||||
*/
|
||||
@FailureExpectedWithNewMetamodel
|
||||
public class PropertyRefTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
|
@ -111,6 +111,7 @@ public class PropertyRefTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@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 class PropertyRefTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.junit.Test;
|
|||
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 class SubselectTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
@FailureExpectedWithNewMetamodel
|
||||
public void testEntitySubselect() {
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
|
@ -89,7 +87,6 @@ public class SubselectTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
@FailureExpectedWithNewMetamodel
|
||||
public void testCustomColumnReadAndWrite() {
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
<class name="Person" table="PROPREF_PERS">
|
||||
<id name="id">
|
||||
<generator class="hilo"/>
|
||||
<generator class="seqhilo"/>
|
||||
</id>
|
||||
<property name="name" length="100"/>
|
||||
<property name="userId" column="person_userid" length="8" unique="true" not-null="true"/>
|
||||
|
@ -39,7 +39,7 @@
|
|||
|
||||
<class name="Address" table="PROPREF_ADDR">
|
||||
<id name="id">
|
||||
<generator class="hilo"/>
|
||||
<generator class="seqhilo"/>
|
||||
</id>
|
||||
<property name="address" length="300"/>
|
||||
<property name="zip" length="5"/>
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
<id name="id" unsaved-value="0"
|
||||
column="bid">
|
||||
<generator class="hilo"/>
|
||||
<generator class="seqhilo"/>
|
||||
</id>
|
||||
|
||||
<property name="name"
|
||||
|
@ -49,7 +49,7 @@
|
|||
|
||||
<id name="id" unsaved-value="0"
|
||||
column="bid">
|
||||
<generator class="hilo"/>
|
||||
<generator class="seqhilo"/>
|
||||
</id>
|
||||
|
||||
<property name="identity"
|
||||
|
|
|
@ -167,7 +167,7 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
|
|||
}
|
||||
this.entityManagerFactoryName = entityManagerFactoryName;
|
||||
if ( metadataImplementor != null ) {
|
||||
applyNamedEntityGraphs( metadataImplementor.getNamedEntityGraphMap().values() );
|
||||
applyNamedEntityGraphs( metadataImplementor.getNamedEntityGraphs().values() );
|
||||
}
|
||||
|
||||
EntityManagerFactoryRegistry.INSTANCE.addEntityManagerFactory( entityManagerFactoryName, this );
|
||||
|
|
|
@ -24,14 +24,14 @@ import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
|
|||
*/
|
||||
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;
|
||||
|
@ -50,9 +50,7 @@ public class BaseFunctionalTestCase extends BaseUnitTestCase {
|
|||
return metadata;
|
||||
}
|
||||
|
||||
protected boolean isMetadataUsed() {
|
||||
return isMetadataUsed;
|
||||
}
|
||||
|
||||
|
||||
//----------------------- services and service registry
|
||||
protected BootstrapServiceRegistry buildBootstrapServiceRegistry() {
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.junit.runner.RunWith;
|
|||
|
||||
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 @@ import org.hibernate.testing.jta.TestingJtaPlatformImpl;
|
|||
@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() {
|
||||
|
|
Loading…
Reference in New Issue