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;
|
int size = implementors.length;
|
||||||
|
|
||||||
CriteriaLoader[] loaders = new CriteriaLoader[size];
|
CriteriaLoader[] loaders = new CriteriaLoader[size];
|
||||||
Set spaces = new HashSet();
|
Set<Serializable> spaces = new HashSet<Serializable>();
|
||||||
for( int i=0; i <size; i++ ) {
|
for( int i=0; i <size; i++ ) {
|
||||||
|
|
||||||
loaders[i] = new CriteriaLoader(
|
loaders[i] = new CriteriaLoader(
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.hibernate.loader.criteria;
|
package org.hibernate.loader.criteria;
|
||||||
|
import java.io.Serializable;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -68,7 +69,7 @@ public class CriteriaLoader extends OuterJoinLoader {
|
||||||
// multithreaded, or cacheable!!
|
// multithreaded, or cacheable!!
|
||||||
|
|
||||||
private final CriteriaQueryTranslator translator;
|
private final CriteriaQueryTranslator translator;
|
||||||
private final Set querySpaces;
|
private final Set<Serializable> querySpaces;
|
||||||
private final Type[] resultTypes;
|
private final Type[] resultTypes;
|
||||||
//the user visible aliases, which are unknown to the superclass,
|
//the user visible aliases, which are unknown to the superclass,
|
||||||
//these are not the actual "physical" SQL aliases
|
//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;
|
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.FetchProfile;
|
||||||
import org.hibernate.metamodel.spi.binding.IdGenerator;
|
import org.hibernate.metamodel.spi.binding.IdGenerator;
|
||||||
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
|
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.binding.TypeDefinition;
|
||||||
|
import org.hibernate.metamodel.spi.relational.Identifier;
|
||||||
import org.hibernate.type.BasicType;
|
import org.hibernate.type.BasicType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,20 +57,20 @@ public interface Metadata {
|
||||||
* Exposes the options used to produce a {@link Metadata} instance.
|
* Exposes the options used to produce a {@link Metadata} instance.
|
||||||
*/
|
*/
|
||||||
public static interface Options {
|
public static interface Options {
|
||||||
public StandardServiceRegistry getServiceRegistry();
|
StandardServiceRegistry getServiceRegistry();
|
||||||
|
|
||||||
public MetadataSourceProcessingOrder getMetadataSourceProcessingOrder();
|
MetadataSourceProcessingOrder getMetadataSourceProcessingOrder();
|
||||||
public NamingStrategy getNamingStrategy();
|
NamingStrategy getNamingStrategy();
|
||||||
public EntityResolver getEntityResolver();
|
EntityResolver getEntityResolver();
|
||||||
public SharedCacheMode getSharedCacheMode();
|
SharedCacheMode getSharedCacheMode();
|
||||||
public AccessType getDefaultAccessType();
|
AccessType getDefaultAccessType();
|
||||||
public boolean useNewIdentifierGenerators();
|
boolean useNewIdentifierGenerators();
|
||||||
public boolean isGloballyQuotedIdentifiers();
|
boolean isGloballyQuotedIdentifiers();
|
||||||
public String getDefaultSchemaName();
|
String getDefaultSchemaName();
|
||||||
public String getDefaultCatalogName();
|
String getDefaultCatalogName();
|
||||||
public MultiTenancyStrategy getMultiTenancyStrategy();
|
MultiTenancyStrategy getMultiTenancyStrategy();
|
||||||
public IndexView getJandexView();
|
IndexView getJandexView();
|
||||||
public List<BasicType> getBasicTypeRegistrations();
|
List<BasicType> getBasicTypeRegistrations();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,14 +78,14 @@ public interface Metadata {
|
||||||
*
|
*
|
||||||
* @return The options.
|
* @return The options.
|
||||||
*/
|
*/
|
||||||
public Options getOptions();
|
Options getOptions();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the builder for {@link SessionFactory} instances based on this metamodel,
|
* Get the builder for {@link SessionFactory} instances based on this metamodel,
|
||||||
*
|
*
|
||||||
* @return The builder for {@link SessionFactory} instances.
|
* @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
|
* 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.
|
* @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
|
* Get the "root" entity binding
|
||||||
* @param entityName
|
* @param entityName
|
||||||
* @return the "root entity binding; simply returns entityBinding if it is the root entity binding
|
* @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);
|
Map<Identifier, SecondaryTable> getSecondaryTables();
|
||||||
|
Map<String, FilterDefinition> getFilterDefinitions();
|
||||||
public TypeDefinition getTypeDefinition(String name);
|
Map<String, NamedEntityGraphDefinition> getNamedEntityGraphs();
|
||||||
|
Map<String, ResultSetMappingDefinition> getResultSetMappingDefinitions();
|
||||||
public Iterable<TypeDefinition> getTypeDefinitions();
|
Map<String,String> getImports();
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -781,13 +781,16 @@ public class Binder {
|
||||||
if ( discriminatorValue != null ) {
|
if ( discriminatorValue != null ) {
|
||||||
rootEntityBinding.setDiscriminatorMatchValue( discriminatorValue );
|
rootEntityBinding.setDiscriminatorMatchValue( discriminatorValue );
|
||||||
}
|
}
|
||||||
else if ( !Modifier.isAbstract(
|
else
|
||||||
bindingContext().locateClassByName( rootEntitySource.getEntityName() )
|
// if ( !Modifier.isAbstract(
|
||||||
.getModifiers()
|
// bindingContext().locateClassByName( rootEntitySource.getEntityName() )
|
||||||
) ) {
|
// .getModifiers()
|
||||||
|
// ) )
|
||||||
|
{
|
||||||
// Use the class name as a default if no discriminator value.
|
// Use the class name as a default if no discriminator value.
|
||||||
// However, skip abstract classes -- obviously no discriminators there.
|
// 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
|
// Configure discriminator hibernate type
|
||||||
typeHelper.bindDiscriminatorType( discriminator, value );
|
typeHelper.bindDiscriminatorType( discriminator, value );
|
||||||
|
@ -969,14 +972,19 @@ public class Binder {
|
||||||
targetColumns
|
targetColumns
|
||||||
);
|
);
|
||||||
SecondaryTable secondaryTable = new SecondaryTable( table, foreignKey );
|
SecondaryTable secondaryTable = new SecondaryTable( table, foreignKey );
|
||||||
|
if(secondaryTableSource.getFetchStyle()!=null)
|
||||||
secondaryTable.setFetchStyle( secondaryTableSource.getFetchStyle() );
|
secondaryTable.setFetchStyle( secondaryTableSource.getFetchStyle() );
|
||||||
secondaryTable.setInverse( secondaryTableSource.isInverse() );
|
secondaryTable.setInverse( secondaryTableSource.isInverse() );
|
||||||
secondaryTable.setOptional( secondaryTableSource.isOptional() );
|
secondaryTable.setOptional( secondaryTableSource.isOptional() );
|
||||||
secondaryTable.setCascadeDeleteEnabled( secondaryTableSource.isCascadeDeleteEnabled() );
|
secondaryTable.setCascadeDeleteEnabled( secondaryTableSource.isCascadeDeleteEnabled() );
|
||||||
|
secondaryTable.setCustomDelete( secondaryTableSource.getCustomSqlDelete() );
|
||||||
|
secondaryTable.setCustomInsert( secondaryTableSource.getCustomSqlInsert() );
|
||||||
|
secondaryTable.setCustomUpdate( secondaryTableSource.getCustomSqlUpdate() );
|
||||||
if ( secondaryTable.isCascadeDeleteEnabled() ) {
|
if ( secondaryTable.isCascadeDeleteEnabled() ) {
|
||||||
foreignKey.setDeleteRule( ForeignKey.ReferentialAction.CASCADE );
|
foreignKey.setDeleteRule( ForeignKey.ReferentialAction.CASCADE );
|
||||||
}
|
}
|
||||||
entityBinding.addSecondaryTable( secondaryTable );
|
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.PluralAttributeIndexBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.PluralAttributeKeyBinding;
|
import org.hibernate.metamodel.spi.binding.PluralAttributeKeyBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.RelationalValueBinding;
|
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.binding.TypeDefinition;
|
||||||
import org.hibernate.metamodel.spi.domain.BasicType;
|
import org.hibernate.metamodel.spi.domain.BasicType;
|
||||||
import org.hibernate.metamodel.spi.domain.SingularAttribute;
|
import org.hibernate.metamodel.spi.domain.SingularAttribute;
|
||||||
import org.hibernate.metamodel.spi.domain.Type;
|
import org.hibernate.metamodel.spi.domain.Type;
|
||||||
import org.hibernate.metamodel.spi.relational.Database;
|
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.Schema;
|
||||||
import org.hibernate.metamodel.spi.relational.Table;
|
import org.hibernate.metamodel.spi.relational.Table;
|
||||||
import org.hibernate.metamodel.spi.source.FilterDefinitionSource;
|
import org.hibernate.metamodel.spi.source.FilterDefinitionSource;
|
||||||
|
@ -136,22 +138,24 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
||||||
private final ObjectNameNormalizer nameNormalizer;
|
private final ObjectNameNormalizer nameNormalizer;
|
||||||
|
|
||||||
private final Map<String, TypeDefinition> typeDefinitionMap = new HashMap<String, TypeDefinition>();
|
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 final Map<String, EntityBinding> entityBindingMap = new HashMap<String, EntityBinding>();
|
||||||
private Map<String, PluralAttributeBinding> collectionBindingMap = new HashMap<String, PluralAttributeBinding>();
|
private final Map<String, PluralAttributeBinding> collectionBindingMap = new HashMap<String, PluralAttributeBinding>();
|
||||||
private Map<String, FetchProfile> fetchProfiles = new HashMap<String, FetchProfile>();
|
private final Map<String, FetchProfile> fetchProfiles = new HashMap<String, FetchProfile>();
|
||||||
private Map<String, String> imports = new HashMap<String, String>();
|
private final Map<String, String> imports = new HashMap<String, String>();
|
||||||
private Map<String, IdGenerator> idGenerators = new HashMap<String, IdGenerator>();
|
private final Map<String, IdGenerator> idGenerators = new HashMap<String, IdGenerator>();
|
||||||
private Map<String, NamedQueryDefinition> namedQueryDefs = new HashMap<String, NamedQueryDefinition>();
|
private final Map<String, NamedQueryDefinition> namedQueryDefs = new HashMap<String, NamedQueryDefinition>();
|
||||||
private Map<String, NamedSQLQueryDefinition> namedNativeQueryDefs = new HashMap<String, NamedSQLQueryDefinition>();
|
private final Map<String, NamedSQLQueryDefinition> namedNativeQueryDefs = new HashMap<String, NamedSQLQueryDefinition>();
|
||||||
private Map<String, ResultSetMappingDefinition> resultSetMappings = new HashMap<String, ResultSetMappingDefinition>();
|
private final Map<String, ResultSetMappingDefinition> resultSetMappings = new HashMap<String, ResultSetMappingDefinition>();
|
||||||
private final Map<String, NamedEntityGraphDefinition> namedEntityGraphMap = new HashMap<String, NamedEntityGraphDefinition>( );
|
private final Map<String, NamedEntityGraphDefinition> namedEntityGraphMap = new HashMap<String, NamedEntityGraphDefinition>( );
|
||||||
|
private final Map<Identifier, SecondaryTable> secondaryTableMap = new HashMap<Identifier, SecondaryTable>( );
|
||||||
|
|
||||||
private boolean globallyQuotedIdentifiers = false;
|
private boolean globallyQuotedIdentifiers = false;
|
||||||
|
|
||||||
public MetadataImpl(MetadataSources metadataSources, Options options) {
|
public MetadataImpl(MetadataSources metadataSources, Options options) {
|
||||||
this.serviceRegistry = options.getServiceRegistry();
|
this.serviceRegistry = options.getServiceRegistry();
|
||||||
|
this.classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.identifierGeneratorFactory = serviceRegistry.getService( MutableIdentifierGeneratorFactory.class );
|
this.identifierGeneratorFactory = serviceRegistry.getService( MutableIdentifierGeneratorFactory.class );
|
||||||
this.database = new Database( options, serviceRegistry.getService( JdbcServices.class ).getJdbcEnvironment() );
|
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>(
|
// this.persisterClassResolverService = new ValueHolder<PersisterClassResolver>(
|
||||||
// new ValueHolder.DeferredInitializer<PersisterClassResolver>() {
|
// new ValueHolder.DeferredInitializer<PersisterClassResolver>() {
|
||||||
// @Override
|
// @Override
|
||||||
|
@ -387,7 +390,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, NamedEntityGraphDefinition> getNamedEntityGraphMap() {
|
public Map<String, NamedEntityGraphDefinition> getNamedEntityGraphs() {
|
||||||
return namedEntityGraphMap;
|
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) {
|
public PluralAttributeBinding getCollection(String collectionRole) {
|
||||||
return collectionBindingMap.get( collectionRole );
|
return collectionBindingMap.get( collectionRole );
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.engine.FetchStyle;
|
import org.hibernate.engine.FetchStyle;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.PrimaryKeyJoinColumn;
|
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.TableSpecification;
|
||||||
import org.hibernate.metamodel.spi.relational.Value;
|
import org.hibernate.metamodel.spi.relational.Value;
|
||||||
import org.hibernate.metamodel.spi.source.ColumnSource;
|
import org.hibernate.metamodel.spi.source.ColumnSource;
|
||||||
|
@ -80,27 +81,42 @@ public class SecondaryTableSourceImpl implements SecondaryTableSource {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getComment() {
|
public String getComment() {
|
||||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FetchStyle getFetchStyle() {
|
public FetchStyle getFetchStyle() {
|
||||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInverse() {
|
public boolean isInverse() {
|
||||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOptional() {
|
public boolean isOptional() {
|
||||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCascadeDeleteEnabled() {
|
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
|
@Override
|
||||||
|
|
|
@ -29,12 +29,17 @@ import org.jboss.jandex.AnnotationInstance;
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
import org.hibernate.AnnotationException;
|
import org.hibernate.AnnotationException;
|
||||||
|
import org.hibernate.MappingException;
|
||||||
|
import org.hibernate.annotations.FetchMode;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext;
|
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.HibernateDotNames;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
||||||
import org.hibernate.metamodel.spi.MetadataImplementor;
|
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.Column;
|
||||||
import org.hibernate.metamodel.spi.relational.Index;
|
import org.hibernate.metamodel.spi.relational.Index;
|
||||||
import org.hibernate.metamodel.spi.relational.ObjectName;
|
import org.hibernate.metamodel.spi.relational.ObjectName;
|
||||||
|
@ -83,11 +88,19 @@ public class TableProcessor {
|
||||||
Schema schema = metadata.getDatabase().getSchema( objectName.getCatalog(), objectName.getSchema() );
|
Schema schema = metadata.getDatabase().getSchema( objectName.getCatalog(), objectName.getSchema() );
|
||||||
Table table = schema.locateTable( objectName.getName() );
|
Table table = schema.locateTable( objectName.getName() );
|
||||||
if ( table != null ) {
|
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(
|
for ( AnnotationInstance indexAnnotation : JandexHelper.getValue(
|
||||||
tableAnnotation,
|
tableAnnotation,
|
||||||
"indexes",
|
"indexes",
|
||||||
|
@ -99,10 +112,61 @@ public class TableProcessor {
|
||||||
if ( StringHelper.isNotEmpty( comment ) ) {
|
if ( StringHelper.isNotEmpty( comment ) ) {
|
||||||
table.addComment( comment.trim() );
|
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) {
|
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 );
|
String[] columnNames = JandexHelper.getValue( indexAnnotation, "columnNames", String[].class );
|
||||||
if ( columnNames == null ) {
|
if ( columnNames == null ) {
|
||||||
LOG.noColumnsSpecifiedForIndex( indexName, table.toLoggableString() );
|
LOG.noColumnsSpecifiedForIndex( indexName, table.toLoggableString() );
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class AnnotationParserHelper {
|
||||||
return createCustomSQL( sqlAnnotation );
|
return createCustomSQL( sqlAnnotation );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CustomSQL createCustomSQL(AnnotationInstance customSqlAnnotation) {
|
public static CustomSQL createCustomSQL(AnnotationInstance customSqlAnnotation) {
|
||||||
if ( customSqlAnnotation == null ) {
|
if ( customSqlAnnotation == null ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import javax.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.IdClass;
|
import javax.persistence.IdClass;
|
||||||
|
import javax.persistence.Index;
|
||||||
import javax.persistence.Inheritance;
|
import javax.persistence.Inheritance;
|
||||||
import javax.persistence.InheritanceType;
|
import javax.persistence.InheritanceType;
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
|
@ -153,6 +154,7 @@ public interface JPADotNames {
|
||||||
DotName GENERATED_VALUE = DotName.createSimple( GeneratedValue.class.getName() );
|
DotName GENERATED_VALUE = DotName.createSimple( GeneratedValue.class.getName() );
|
||||||
DotName ID = DotName.createSimple( Id.class.getName() );
|
DotName ID = DotName.createSimple( Id.class.getName() );
|
||||||
DotName ID_CLASS = DotName.createSimple( IdClass.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 = DotName.createSimple( Inheritance.class.getName() );
|
||||||
DotName INHERITANCE_TYPE = DotName.createSimple( InheritanceType.class.getName() );
|
DotName INHERITANCE_TYPE = DotName.createSimple( InheritanceType.class.getName() );
|
||||||
DotName JOIN_COLUMN = DotName.createSimple( JoinColumn.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>();
|
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
|
||||||
MockHelper.stringValue( "name", uniqueConstraint.getName(), annotationValueList );
|
MockHelper.stringValue( "name", uniqueConstraint.getName(), annotationValueList );
|
||||||
MockHelper.stringArrayValue( "columnNames", uniqueConstraint.getColumnName(), annotationValueList );
|
MockHelper.stringArrayValue( "columnNames", uniqueConstraint.getColumnName(), annotationValueList );
|
||||||
return
|
return create( UNIQUE_CONSTRAINT, target,
|
||||||
create( UNIQUE_CONSTRAINT, target,
|
|
||||||
annotationValueList );
|
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.JaxbFetchStyleAttribute;
|
||||||
import org.hibernate.jaxb.spi.hbm.JaxbJoinElement;
|
import org.hibernate.jaxb.spi.hbm.JaxbJoinElement;
|
||||||
import org.hibernate.jaxb.spi.hbm.JaxbOnDeleteAttribute;
|
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.TableSpecification;
|
||||||
import org.hibernate.metamodel.spi.relational.Value;
|
import org.hibernate.metamodel.spi.relational.Value;
|
||||||
import org.hibernate.metamodel.spi.source.ColumnSource;
|
import org.hibernate.metamodel.spi.source.ColumnSource;
|
||||||
|
@ -145,6 +146,22 @@ class SecondaryTableSourceImpl extends AbstractHbmSourceNode implements Secondar
|
||||||
return fkJoinColumnResolutionDelegate;
|
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() {
|
public String getLogicalTableNameForContainedColumns() {
|
||||||
return TableSource.class.isInstance( joinTable )
|
return TableSource.class.isInstance( joinTable )
|
||||||
? ( (TableSource) joinTable ).getExplicitTableName()
|
? ( (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.FetchProfile;
|
||||||
import org.hibernate.metamodel.spi.binding.IdGenerator;
|
import org.hibernate.metamodel.spi.binding.IdGenerator;
|
||||||
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
|
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.binding.TypeDefinition;
|
||||||
import org.hibernate.metamodel.spi.relational.Database;
|
import org.hibernate.metamodel.spi.relational.Database;
|
||||||
import org.hibernate.metamodel.spi.source.BindingContext;
|
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 addEntity(EntityBinding entityBinding);
|
||||||
|
|
||||||
|
public void addSecondaryTable(SecondaryTable secondaryTable);
|
||||||
|
|
||||||
public void addCollection(PluralAttributeBinding collectionBinding);
|
public void addCollection(PluralAttributeBinding collectionBinding);
|
||||||
|
|
||||||
public void addFetchProfile(FetchProfile profile);
|
public void addFetchProfile(FetchProfile profile);
|
||||||
|
|
|
@ -804,8 +804,7 @@ public class EntityBinding extends AbstractAttributeBindingContainer implements
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isClassOrSuperclassSecondaryTable(SecondaryTable secondaryTable) {
|
public boolean isClassOrSuperclassSecondaryTable(SecondaryTable secondaryTable) {
|
||||||
String secondaryTableName = secondaryTable.getSecondaryTableReference().getLogicalName().getText();
|
return secondaryTables.containsKey( secondaryTable.getSecondaryTableReference().getLogicalName() ) ||
|
||||||
return secondaryTables.containsKey( Identifier.toIdentifier( secondaryTableName ) ) ||
|
|
||||||
( superEntityBinding != null && superEntityBinding.isClassOrSuperclassSecondaryTable( secondaryTable ) );
|
( superEntityBinding != null && superEntityBinding.isClassOrSuperclassSecondaryTable( secondaryTable ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,10 +33,13 @@ import org.hibernate.metamodel.spi.relational.TableSpecification;
|
||||||
public class SecondaryTable {
|
public class SecondaryTable {
|
||||||
private final TableSpecification secondaryTableReference;
|
private final TableSpecification secondaryTableReference;
|
||||||
private final ForeignKey foreignKeyReference;
|
private final ForeignKey foreignKeyReference;
|
||||||
private FetchStyle fetchStyle;
|
private FetchStyle fetchStyle = FetchStyle.JOIN;
|
||||||
private boolean isInverse;
|
private boolean isInverse = false;
|
||||||
private boolean isOptional;
|
private boolean isOptional = true;
|
||||||
private boolean isCascadeDeleteEnabled;
|
private boolean isCascadeDeleteEnabled;
|
||||||
|
private CustomSQL customInsert;
|
||||||
|
private CustomSQL customUpdate;
|
||||||
|
private CustomSQL customDelete;
|
||||||
|
|
||||||
public SecondaryTable(TableSpecification secondaryTableReference, ForeignKey foreignKeyReference) {
|
public SecondaryTable(TableSpecification secondaryTableReference, ForeignKey foreignKeyReference) {
|
||||||
this.secondaryTableReference = secondaryTableReference;
|
this.secondaryTableReference = secondaryTableReference;
|
||||||
|
@ -86,4 +89,28 @@ public class SecondaryTable {
|
||||||
// TODO: need to check attribute bindings using this table
|
// TODO: need to check attribute bindings using this table
|
||||||
return false;
|
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 Origin getOrigin();
|
||||||
public MappingException makeMappingException(String message);
|
public MappingException makeMappingException(String message);
|
||||||
public MappingException makeMappingException(String message, Exception cause);
|
public MappingException makeMappingException(String message, Exception cause);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ package org.hibernate.metamodel.spi.source;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.engine.FetchStyle;
|
import org.hibernate.engine.FetchStyle;
|
||||||
|
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
@ -56,4 +57,25 @@ public interface SecondaryTableSource extends ForeignKeyContributingSource {
|
||||||
public boolean isOptional();
|
public boolean isOptional();
|
||||||
|
|
||||||
public boolean isCascadeDeleteEnabled();
|
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,22 +3800,26 @@ public abstract class AbstractEntityPersister
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected JoinFragment createJoin(String name, boolean innerJoin, boolean includeSubclasses) {
|
protected JoinFragment createJoin(final String name, final boolean innerJoin, final boolean includeSubclasses) {
|
||||||
final String[] idCols = StringHelper.qualify( name, getIdentifierColumnNames() ); //all joins join to the pk of the driving table
|
|
||||||
final JoinFragment join = getFactory().getDialect().createOuterJoinFragment();
|
final JoinFragment join = getFactory().getDialect().createOuterJoinFragment();
|
||||||
final int tableSpan = getSubclassTableSpan();
|
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!
|
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 ) );
|
( includeSubclasses && !isSubclassTableSequentialSelect( j ) && !isSubclassTableLazy( j ) );
|
||||||
if ( joinIsIncluded ) {
|
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 ),
|
generateTableAlias( name, j ),
|
||||||
idCols,
|
idCols,
|
||||||
getSubclassTableKeyColumns( j ),
|
getSubclassTableKeyColumns( j ),
|
||||||
innerJoin && isClassOrSuperclassTable( j ) && !isInverseTable( j ) && !isNullableTable( j ) ?
|
joinType
|
||||||
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
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return join;
|
return join;
|
||||||
|
|
|
@ -267,8 +267,9 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
||||||
joinIter = persistentClass.getSubclassJoinClosureIterator();
|
joinIter = persistentClass.getSubclassJoinClosureIterator();
|
||||||
while ( joinIter.hasNext() ) {
|
while ( joinIter.hasNext() ) {
|
||||||
Join join = (Join) joinIter.next();
|
Join join = (Join) joinIter.next();
|
||||||
isConcretes.add( persistentClass.isClassOrSuperclassJoin(join) );
|
isConcretes.add( persistentClass.isClassOrSuperclassJoin(join) ); //if the secondary table is defined in the current class or its super class
|
||||||
isDeferreds.add( join.isSequentialSelect() );
|
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() );
|
isInverses.add( join.isInverse() );
|
||||||
isNullables.add( join.isOptional() );
|
isNullables.add( join.isOptional() );
|
||||||
isLazies.add( lazyAvailable && join.isLazy() );
|
isLazies.add( lazyAvailable && join.isLazy() );
|
||||||
|
@ -515,9 +516,9 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
||||||
cascadeDeleteEnabled[j] = join.isCascadeDeleteEnabled() &&
|
cascadeDeleteEnabled[j] = join.isCascadeDeleteEnabled() &&
|
||||||
factory.getDialect().supportsCascadeDelete();
|
factory.getDialect().supportsCascadeDelete();
|
||||||
|
|
||||||
initializeCustomSql( entityBinding.getCustomInsert(), j, customSQLInsert, insertCallable, insertResultCheckStyles );
|
initializeCustomSql( join.getCustomInsert(), j, customSQLInsert, insertCallable, insertResultCheckStyles );
|
||||||
initializeCustomSql( entityBinding.getCustomUpdate(), j, customSQLUpdate, updateCallable, updateResultCheckStyles );
|
initializeCustomSql( join.getCustomUpdate(), j, customSQLUpdate, updateCallable, updateResultCheckStyles );
|
||||||
initializeCustomSql( entityBinding.getCustomDelete(), j, customSQLDelete, deleteCallable, deleteResultCheckStyles );
|
initializeCustomSql( join.getCustomDelete(), j, customSQLDelete, deleteCallable, deleteResultCheckStyles );
|
||||||
|
|
||||||
final List<org.hibernate.metamodel.spi.relational.Column> joinColumns = join.getForeignKeyReference().getSourceColumns();
|
final List<org.hibernate.metamodel.spi.relational.Column> joinColumns = join.getForeignKeyReference().getSourceColumns();
|
||||||
keyColumnNames[j] = new String[ joinColumns.size() ];
|
keyColumnNames[j] = new String[ joinColumns.size() ];
|
||||||
|
@ -566,9 +567,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
||||||
isInverses.add( join.isInverse() );
|
isInverses.add( join.isInverse() );
|
||||||
isNullables.add( join.isOptional() );
|
isNullables.add( join.isOptional() );
|
||||||
isLazies.add( lazyAvailable && join.isLazy() );
|
isLazies.add( lazyAvailable && join.isLazy() );
|
||||||
if ( isDeferred && !isConcrete ) {
|
hasDeferred = isDeferred && !isConcrete;
|
||||||
hasDeferred = true;
|
|
||||||
}
|
|
||||||
subclassTables.add( join.getSecondaryTableReference().getQualifiedName( factory.getDialect() ) );
|
subclassTables.add( join.getSecondaryTableReference().getQualifiedName( factory.getDialect() ) );
|
||||||
final List<org.hibernate.metamodel.spi.relational.Column> joinColumns = join.getForeignKeyReference().getSourceColumns();
|
final List<org.hibernate.metamodel.spi.relational.Column> joinColumns = join.getForeignKeyReference().getSourceColumns();
|
||||||
String[] keyCols = new String[ joinColumns.size() ];
|
String[] keyCols = new String[ joinColumns.size() ];
|
||||||
|
@ -686,15 +685,16 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
||||||
ArrayList<Integer> propertyJoinNumbers = new ArrayList<Integer>();
|
ArrayList<Integer> propertyJoinNumbers = new ArrayList<Integer>();
|
||||||
|
|
||||||
for ( AttributeBinding attributeBinding : entityBinding.getNonIdEntitiesAttributeBindingClosure() ) {
|
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() ) {
|
if ( attributeBinding.getAttribute().isSingular() ) {
|
||||||
SingularAttributeBinding singularAttributeBinding = (SingularAttributeBinding) attributeBinding;
|
SingularAttributeBinding singularAttributeBinding = (SingularAttributeBinding) attributeBinding;
|
||||||
int join = entityBinding.getSecondaryTableNumber( singularAttributeBinding );
|
int join = entityBinding.getSecondaryTableNumber( singularAttributeBinding );
|
||||||
propertyJoinNumbers.add( join );
|
propertyJoinNumbers.add( join );
|
||||||
// We need the name of the actual entity that contains this attribute binding.
|
// We need the name of the actual entity that contains this attribute binding.
|
||||||
final String entityName = attributeBinding.getContainer().seekEntityBinding().getEntityName();
|
//TODO it should be folder.children but now it is ".children"
|
||||||
String path = StringHelper.isEmpty( attributeBinding.getContainer().getPathBase() ) ?
|
|
||||||
entityName + '.' + attributeBinding.getAttribute().getName() :
|
|
||||||
entityName + '.' + attributeBinding.getContainer().getPathBase() + '.' + attributeBinding.getAttribute().getName();
|
|
||||||
propertyTableNumbersByNameAndSubclass.put( path, join );
|
propertyTableNumbersByNameAndSubclass.put( path, join );
|
||||||
for ( RelationalValueBinding relationalValueBinding : singularAttributeBinding.getRelationalValueBindings() ) {
|
for ( RelationalValueBinding relationalValueBinding : singularAttributeBinding.getRelationalValueBindings() ) {
|
||||||
if ( DerivedValue.class.isInstance( relationalValueBinding.getValue() ) ) {
|
if ( DerivedValue.class.isInstance( relationalValueBinding.getValue() ) ) {
|
||||||
|
@ -707,10 +707,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
propertyJoinNumbers.add( 0 );
|
propertyJoinNumbers.add( 0 );
|
||||||
propertyTableNumbersByNameAndSubclass.put(
|
propertyTableNumbersByNameAndSubclass.put( path, 0 );
|
||||||
attributeBinding.getContainer().getPathBase() + '.' + attributeBinding.getAttribute().getName(),
|
|
||||||
0
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
subclassColumnTableNumberClosure = ArrayHelper.toIntArray(columnJoinNumbers);
|
subclassColumnTableNumberClosure = ArrayHelper.toIntArray(columnJoinNumbers);
|
||||||
|
@ -1059,7 +1056,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
||||||
}
|
}
|
||||||
return qualifiedTableNames[ propertyTableNumbers[ index ] ];
|
return qualifiedTableNames[ propertyTableNumbers[ index ] ];
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void postInstantiate() {
|
public void postInstantiate() {
|
||||||
super.postInstantiate();
|
super.postInstantiate();
|
||||||
if (hasSequentialSelects) {
|
if (hasSequentialSelects) {
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.annotations.DiscriminatorFormula;
|
import org.hibernate.annotations.DiscriminatorFormula;
|
||||||
import org.hibernate.annotations.DiscriminatorOptions;
|
import org.hibernate.annotations.DiscriminatorOptions;
|
||||||
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.EntityDiscriminator;
|
import org.hibernate.metamodel.spi.binding.EntityDiscriminator;
|
||||||
|
@ -168,7 +169,7 @@ public class InheritanceBindingTest extends BaseAnnotationBindingTestCase {
|
||||||
EntityBinding subclassOfSubclassEntityBinding = getEntityBinding( SubclassOfSubclassOfSingleTableInheritance.class );
|
EntityBinding subclassOfSubclassEntityBinding = getEntityBinding( SubclassOfSubclassOfSingleTableInheritance.class );
|
||||||
|
|
||||||
assertTrue( rootEntityBinding.isRoot() );
|
assertTrue( rootEntityBinding.isRoot() );
|
||||||
assertEquals( rootEntityBinding.getEntity().getName(), rootEntityBinding.getDiscriminatorMatchValue() );
|
assertEquals( StringHelper.unqualify( rootEntityBinding.getEntity().getName() ), rootEntityBinding.getDiscriminatorMatchValue() );
|
||||||
assertNull( rootEntityBinding.getSuperEntityBinding() );
|
assertNull( rootEntityBinding.getSuperEntityBinding() );
|
||||||
assertSame( rootEntityBinding, getRootEntityBinding( RootOfSingleTableInheritance.class ) );
|
assertSame( rootEntityBinding, getRootEntityBinding( RootOfSingleTableInheritance.class ) );
|
||||||
assertTrue( rootEntityBinding.isPolymorphic() );
|
assertTrue( rootEntityBinding.isPolymorphic() );
|
||||||
|
|
|
@ -36,6 +36,7 @@ import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.dialect.HSQLDialect;
|
import org.hibernate.dialect.HSQLDialect;
|
||||||
import org.hibernate.dialect.function.SQLFunctionRegistry;
|
import org.hibernate.dialect.function.SQLFunctionRegistry;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
|
import org.hibernate.metamodel.MetadataSources;
|
||||||
import org.hibernate.persister.entity.PropertyMapping;
|
import org.hibernate.persister.entity.PropertyMapping;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.sql.ordering.antlr.ColumnMapper;
|
import org.hibernate.sql.ordering.antlr.ColumnMapper;
|
||||||
|
@ -113,7 +114,13 @@ public class TemplateTest extends BaseUnitTestCase {
|
||||||
Configuration cfg = new Configuration();
|
Configuration cfg = new Configuration();
|
||||||
cfg.setProperty( AvailableSettings.DIALECT, DIALECT.getClass().getName() );
|
cfg.setProperty( AvailableSettings.DIALECT, DIALECT.getClass().getName() );
|
||||||
ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
|
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
|
@AfterClass
|
||||||
|
|
|
@ -45,6 +45,8 @@ import org.hibernate.Session;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
|
import org.hibernate.metamodel.MetadataSources;
|
||||||
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.testing.DialectChecks;
|
import org.hibernate.testing.DialectChecks;
|
||||||
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
||||||
import org.hibernate.testing.RequiresDialectFeature;
|
import org.hibernate.testing.RequiresDialectFeature;
|
||||||
|
@ -101,7 +103,6 @@ public class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@RequiresDialectFeature( DialectChecks.SupportsExpectedLobUsagePattern.class )
|
@RequiresDialectFeature( DialectChecks.SupportsExpectedLobUsagePattern.class )
|
||||||
@FailureExpectedWithNewMetamodel
|
|
||||||
public void testVersioning() throws Exception {
|
public void testVersioning() throws Exception {
|
||||||
Forest forest = new Forest();
|
Forest forest = new Forest();
|
||||||
forest.setName( "Fontainebleau" );
|
forest.setName( "Fontainebleau" );
|
||||||
|
@ -328,7 +329,6 @@ public class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpectedWithNewMetamodel
|
|
||||||
public void testCascadedDeleteOfChildEntitiesBug2() {
|
public void testCascadedDeleteOfChildEntitiesBug2() {
|
||||||
// Relationship is one SoccerTeam to many Players.
|
// Relationship is one SoccerTeam to many Players.
|
||||||
// Create a SoccerTeam (parent) and three Players (child).
|
// Create a SoccerTeam (parent) and three Players (child).
|
||||||
|
@ -379,7 +379,6 @@ public class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpectedWithNewMetamodel
|
|
||||||
public void testCascadedDeleteOfChildOneToOne() {
|
public void testCascadedDeleteOfChildOneToOne() {
|
||||||
// create two single player teams (for one versus one match of soccer)
|
// create two single player teams (for one versus one match of soccer)
|
||||||
// and associate teams with players via the special OneVOne methods.
|
// and associate teams with players via the special OneVOne methods.
|
||||||
|
@ -454,7 +453,7 @@ public class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
|
||||||
assertEquals( 1, count );
|
assertEquals( 1, count );
|
||||||
s.disableFilter( "betweenLength" );
|
s.disableFilter( "betweenLength" );
|
||||||
s.enableFilter( "minLength" ).setParameter( "minLength", 5 );
|
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 );
|
assertEquals( 2l, count );
|
||||||
s.disableFilter( "minLength" );
|
s.disableFilter( "minLength" );
|
||||||
tx.rollback();
|
tx.rollback();
|
||||||
|
@ -466,7 +465,6 @@ public class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
|
||||||
* defined on a parent MappedSuperclass(s)
|
* defined on a parent MappedSuperclass(s)
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@FailureExpectedWithNewMetamodel
|
|
||||||
public void testInheritFiltersFromMappedSuperclass() throws Exception {
|
public void testInheritFiltersFromMappedSuperclass() throws Exception {
|
||||||
Session s;
|
Session s;
|
||||||
Transaction tx;
|
Transaction tx;
|
||||||
|
@ -500,9 +498,9 @@ public class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
|
||||||
s.disableFilter( "byName" );
|
s.disableFilter( "byName" );
|
||||||
|
|
||||||
s.enableFilter( "byCategory" ).setParameter( "category", "Industrial" );
|
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 );
|
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 );
|
assertEquals( 1, count );
|
||||||
s.disableFilter( "byCategory" );
|
s.disableFilter( "byCategory" );
|
||||||
|
|
||||||
|
@ -655,10 +653,19 @@ public class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testTypeDefWithoutNameAndDefaultForTypeAttributes() {
|
public void testTypeDefWithoutNameAndDefaultForTypeAttributes() {
|
||||||
SessionFactory sf=null;
|
SessionFactory sf=null;
|
||||||
|
ServiceRegistry serviceRegistry= null;
|
||||||
try {
|
try {
|
||||||
Configuration config = new Configuration();
|
Configuration config = new Configuration();
|
||||||
config.addAnnotatedClass(LocalContactDetails.class);
|
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() );
|
||||||
sf = config.buildSessionFactory( 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");
|
fail("Did not throw expected exception");
|
||||||
}
|
}
|
||||||
catch( AnnotationException ex ) {
|
catch( AnnotationException ex ) {
|
||||||
|
@ -669,6 +676,9 @@ public class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
|
||||||
if( sf != null){
|
if( sf != null){
|
||||||
sf.close();
|
sf.close();
|
||||||
}
|
}
|
||||||
|
if( serviceRegistry != null ){
|
||||||
|
ServiceRegistryBuilder.destroy( serviceRegistry );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,9 @@ import org.junit.Test;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.cfg.Environment;
|
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.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
|
|
||||||
|
@ -39,20 +42,37 @@ import static org.junit.Assert.fail;
|
||||||
* @author Guenther Demetz
|
* @author Guenther Demetz
|
||||||
*/
|
*/
|
||||||
public class HibernateAnnotationMappingTest extends BaseUnitTestCase {
|
public class HibernateAnnotationMappingTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-7446" )
|
@TestForIssue(jiraKey = "HHH-7446")
|
||||||
public void testUniqueConstraintAnnotationOnNaturalIds() throws Exception {
|
public void testUniqueConstraintAnnotationOnNaturalIds() throws Exception {
|
||||||
Configuration configuration = new Configuration();
|
Configuration configuration = new Configuration();
|
||||||
configuration.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
configuration.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||||
configuration.addAnnotatedClass(Month.class);
|
ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( configuration.getProperties() );
|
||||||
SessionFactory sf = null;
|
SessionFactory sf = null;
|
||||||
try {
|
try {
|
||||||
sf = configuration.buildSessionFactory();
|
if ( isMetadataUsed ) {
|
||||||
sf.close();
|
MetadataSources metadataSources = new MetadataSources( serviceRegistry );
|
||||||
|
sf = metadataSources.addAnnotatedClass( Month.class ).buildMetadata().buildSessionFactory();
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
configuration.addAnnotatedClass( Month.class );
|
||||||
|
sf = configuration.buildSessionFactory();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (ConcurrentModificationException e) {
|
catch ( ConcurrentModificationException e ) {
|
||||||
fail(e.toString());
|
fail( e.toString() );
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
if( sf != null ){
|
||||||
|
sf.close();
|
||||||
|
}
|
||||||
|
if( serviceRegistry != null ){
|
||||||
|
ServiceRegistryBuilder.destroy( serviceRegistry );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import javax.persistence.Table;
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@DiscriminatorValue("D")
|
@DiscriminatorValue("D")
|
||||||
@SecondaryTable(name = "DocumentMixed")
|
@SecondaryTable(name = "DocumentSecondaryTable")
|
||||||
@Table(name="Document_Wrong") //illegal use, a warn is raised
|
@Table(name="Document_Wrong") //illegal use, a warn is raised
|
||||||
public class Document extends File {
|
public class Document extends File {
|
||||||
private int size;
|
private int size;
|
||||||
|
@ -24,7 +24,7 @@ public class Document extends File {
|
||||||
this.size = size;
|
this.size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Column(table = "DocumentMixed", name="doc_size", nullable = false)
|
@Column(table = "DocumentSecondaryTable", name="doc_size", nullable = false)
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,8 @@ import javax.persistence.Table;
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||||
@Table(name = "FileMixed")
|
@Table(name = "File")
|
||||||
@SecondaryTable(name = "FileFolderMixed")
|
@SecondaryTable(name = "FileSecondaryTable")
|
||||||
@DiscriminatorColumn(length = 1)
|
@DiscriminatorColumn(length = 1)
|
||||||
public abstract class File {
|
public abstract class File {
|
||||||
private String name;
|
private String name;
|
||||||
|
@ -39,7 +39,7 @@ public abstract class File {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(table = "FileFolderMixed")
|
@JoinColumn(table = "FileSecondaryTable")
|
||||||
public Folder getParent() {
|
public Folder getParent() {
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ import org.junit.Test;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.exception.SQLGrammarException;
|
import org.hibernate.exception.SQLGrammarException;
|
||||||
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -42,7 +41,6 @@ import static org.junit.Assert.fail;
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
@FailureExpectedWithNewMetamodel
|
|
||||||
public class SubclassTest extends BaseCoreFunctionalTestCase {
|
public class SubclassTest extends BaseCoreFunctionalTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testDefault() throws Exception {
|
public void testDefault() throws Exception {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import javax.persistence.SecondaryTable;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@DiscriminatorValue("L")
|
@DiscriminatorValue("L")
|
||||||
@SecondaryTable(name = "SymbolicLinkMixed")
|
@SecondaryTable(name = "SymbolicLinkSecondaryTable")
|
||||||
public class SymbolicLink extends File {
|
public class SymbolicLink extends File {
|
||||||
|
|
||||||
File target;
|
File target;
|
||||||
|
@ -21,7 +21,7 @@ public class SymbolicLink extends File {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ManyToOne(optional = false)
|
@ManyToOne(optional = false)
|
||||||
@JoinColumn(table = "SymbolicLinkMixed")
|
@JoinColumn(table = "SymbolicLinkSecondaryTable")
|
||||||
public File getTarget() {
|
public File getTarget() {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,13 @@ import org.hibernate.annotations.Tables;
|
||||||
@SecondaryTable(name = "`Cat nbr1`"),
|
@SecondaryTable(name = "`Cat nbr1`"),
|
||||||
@SecondaryTable(name = "Cat2", uniqueConstraints = {@UniqueConstraint(columnNames = {"storyPart2"})})
|
@SecondaryTable(name = "Cat2", uniqueConstraints = {@UniqueConstraint(columnNames = {"storyPart2"})})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Tables( {
|
@Tables( {
|
||||||
@Table(appliesTo = "Cat", indexes = @Index(name = "secondname",
|
@Table(appliesTo = "Cat", indexes = @Index(name = "secondname",
|
||||||
columnNames = "secondName"), comment = "My cat table" ),
|
columnNames = "secondName"), comment = "My cat table" ),
|
||||||
|
|
||||||
@Table(appliesTo = "Cat2", foreignKey = @ForeignKey(name="FK_CAT2_CAT"), fetch = FetchMode.SELECT,
|
@Table(appliesTo = "Cat2", foreignKey = @ForeignKey(name="FK_CAT2_CAT"), fetch = FetchMode.SELECT,
|
||||||
sqlInsert=@SQLInsert(sql="insert into Cat2(storyPart2, id) values(upper(?), ?)") )
|
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.Table;
|
||||||
import org.hibernate.metamodel.spi.relational.TableSpecification;
|
import org.hibernate.metamodel.spi.relational.TableSpecification;
|
||||||
import org.hibernate.test.util.SchemaUtil;
|
import org.hibernate.test.util.SchemaUtil;
|
||||||
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -53,7 +52,6 @@ import org.junit.Test;
|
||||||
*/
|
*/
|
||||||
public class JoinTest extends BaseCoreFunctionalTestCase {
|
public class JoinTest extends BaseCoreFunctionalTestCase {
|
||||||
@Test
|
@Test
|
||||||
// @FailureExpectedWithNewMetamodel
|
|
||||||
public void testDefaultValue() throws Exception {
|
public void testDefaultValue() throws Exception {
|
||||||
TableSpecification joinTable = SchemaUtil.getEntityBinding( Life.class, metadata() ).locateTable( "ExtendedLife" );
|
TableSpecification joinTable = SchemaUtil.getEntityBinding( Life.class, metadata() ).locateTable( "ExtendedLife" );
|
||||||
assertNotNull( joinTable );
|
assertNotNull( joinTable );
|
||||||
|
@ -77,7 +75,6 @@ public class JoinTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
// @FailureExpectedWithNewMetamodel
|
|
||||||
public void testCompositePK() throws Exception {
|
public void testCompositePK() throws Exception {
|
||||||
if ( isMetadataUsed() ) {
|
if ( isMetadataUsed() ) {
|
||||||
SecondaryTable secondaryTable =
|
SecondaryTable secondaryTable =
|
||||||
|
@ -144,7 +141,6 @@ public class JoinTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpectedWithNewMetamodel( message = "sequential selects not supported yet.")
|
|
||||||
public void testManyToOne() throws Exception {
|
public void testManyToOne() throws Exception {
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Transaction tx = s.beginTransaction();
|
Transaction tx = s.beginTransaction();
|
||||||
|
@ -209,7 +205,6 @@ public class JoinTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpectedWithNewMetamodel
|
|
||||||
public void testFetchModeOnSecondaryTable() throws Exception {
|
public void testFetchModeOnSecondaryTable() throws Exception {
|
||||||
Cat cat = new Cat();
|
Cat cat = new Cat();
|
||||||
cat.setStoryPart2( "My long story" );
|
cat.setStoryPart2( "My long story" );
|
||||||
|
@ -228,7 +223,6 @@ public class JoinTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpectedWithNewMetamodel
|
|
||||||
public void testCustomSQL() throws Exception {
|
public void testCustomSQL() throws Exception {
|
||||||
Cat cat = new Cat();
|
Cat cat = new Cat();
|
||||||
String storyPart2 = "My long story";
|
String storyPart2 = "My long story";
|
||||||
|
|
|
@ -9,9 +9,12 @@ import javax.persistence.UniqueConstraint;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.AnnotationException;
|
import org.hibernate.AnnotationException;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
|
import org.hibernate.metamodel.MetadataSources;
|
||||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||||
|
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
|
|
||||||
|
@ -23,6 +26,7 @@ public class UniqueConstraintValidationTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Test(expected = AnnotationException.class)
|
@Test(expected = AnnotationException.class)
|
||||||
@TestForIssue(jiraKey = "HHH-4084")
|
@TestForIssue(jiraKey = "HHH-4084")
|
||||||
|
@FailureExpectedWithNewMetamodel
|
||||||
public void testUniqueConstraintWithEmptyColumnName() {
|
public void testUniqueConstraintWithEmptyColumnName() {
|
||||||
buildSessionFactory(EmptyColumnNameEntity.class);
|
buildSessionFactory(EmptyColumnNameEntity.class);
|
||||||
}
|
}
|
||||||
|
@ -33,18 +37,28 @@ public class UniqueConstraintValidationTest extends BaseUnitTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = AnnotationException.class)
|
@Test(expected = AnnotationException.class)
|
||||||
|
@FailureExpectedWithNewMetamodel
|
||||||
public void testUniqueConstraintWithNotExistsColumnName() {
|
public void testUniqueConstraintWithNotExistsColumnName() {
|
||||||
buildSessionFactory(NotExistsColumnEntity.class);
|
buildSessionFactory(NotExistsColumnEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildSessionFactory(Class<?> entity) {
|
private void buildSessionFactory(Class<?> entity) {
|
||||||
Configuration cfg = new Configuration();
|
if ( isMetadataUsed ) {
|
||||||
cfg.addAnnotatedClass(entity);
|
StandardServiceRegistry registry = new StandardServiceRegistryBuilder().build();
|
||||||
cfg.buildMappings();
|
MetadataSources metadataSources = new MetadataSources( registry );
|
||||||
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder()
|
metadataSources.addAnnotatedClass( entity );
|
||||||
.applySettings(cfg.getProperties()).build();
|
metadataSources.buildMetadata();
|
||||||
cfg.buildSessionFactory(serviceRegistry).close();
|
StandardServiceRegistryBuilder.destroy( registry );
|
||||||
serviceRegistry.destroy();
|
}
|
||||||
|
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
|
@Entity
|
||||||
|
|
|
@ -42,7 +42,6 @@ import static org.junit.Assert.assertTrue;
|
||||||
/**
|
/**
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
*/
|
*/
|
||||||
//@FailureExpectedWithNewMetamodel
|
|
||||||
public class ExtraLazyTest extends BaseCoreFunctionalTestCase {
|
public class ExtraLazyTest extends BaseCoreFunctionalTestCase {
|
||||||
@Override
|
@Override
|
||||||
public String[] getMappings() {
|
public String[] getMappings() {
|
||||||
|
|
|
@ -28,7 +28,6 @@ import org.junit.Test;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.id.enhanced.TableGenerator;
|
import org.hibernate.id.enhanced.TableGenerator;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
|
||||||
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||||
|
@ -38,7 +37,6 @@ import static org.junit.Assert.assertEquals;
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
@FailureExpectedWithNewMetamodel
|
|
||||||
public class BasicTableTest extends BaseCoreFunctionalTestCase {
|
public class BasicTableTest extends BaseCoreFunctionalTestCase {
|
||||||
@Override
|
@Override
|
||||||
public String[] getMappings() {
|
public String[] getMappings() {
|
||||||
|
|
|
@ -29,7 +29,6 @@ import org.hibernate.Session;
|
||||||
import org.hibernate.id.enhanced.OptimizerFactory;
|
import org.hibernate.id.enhanced.OptimizerFactory;
|
||||||
import org.hibernate.id.enhanced.TableGenerator;
|
import org.hibernate.id.enhanced.TableGenerator;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
|
||||||
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||||
|
@ -39,7 +38,6 @@ import static org.junit.Assert.assertEquals;
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
@FailureExpectedWithNewMetamodel
|
|
||||||
public class HiLoTableTest extends BaseCoreFunctionalTestCase {
|
public class HiLoTableTest extends BaseCoreFunctionalTestCase {
|
||||||
@Override
|
@Override
|
||||||
public String[] getMappings() {
|
public String[] getMappings() {
|
||||||
|
|
|
@ -29,12 +29,16 @@ import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.Transaction;
|
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 org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
@SuppressWarnings( {"UnnecessaryBoxing"})
|
@SuppressWarnings( {"UnnecessaryBoxing"})
|
||||||
public class ABCTest extends LegacyTestCase {
|
public class ABCTest extends LegacyTestCase {
|
||||||
|
@ -79,16 +83,16 @@ public class ABCTest extends LegacyTestCase {
|
||||||
@Test
|
@Test
|
||||||
@FailureExpectedWithNewMetamodel
|
@FailureExpectedWithNewMetamodel
|
||||||
public void testHigherLevelIndexDefinition() throws Throwable {
|
public void testHigherLevelIndexDefinition() throws Throwable {
|
||||||
String[] commands = configuration().generateSchemaCreationScript( getDialect() );
|
for ( Schema schema : metadata().getDatabase().getSchemas() ) {
|
||||||
int max = commands.length;
|
for ( Table table : schema.getTables() ) {
|
||||||
boolean found = false;
|
for ( Index index : table.getIndexes() ) {
|
||||||
for (int indx = 0; indx < max; indx++) {
|
if ( index.getName().equals( "indx_a_name" ) ) {
|
||||||
System.out.println("Checking command : " + commands[indx]);
|
return;
|
||||||
found = commands[indx].indexOf("create index indx_a_name") >= 0;
|
}
|
||||||
if (found)
|
}
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
assertTrue("Unable to locate indx_a_name index creation", found);
|
fail( "Unable to locate indx_a_name index creation" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -37,7 +37,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
/**
|
/**
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
*/
|
*/
|
||||||
@FailureExpectedWithNewMetamodel
|
|
||||||
public class MapIndexFormulaTest extends BaseCoreFunctionalTestCase {
|
public class MapIndexFormulaTest extends BaseCoreFunctionalTestCase {
|
||||||
@Override
|
@Override
|
||||||
public String[] getMappings() {
|
public String[] getMappings() {
|
||||||
|
@ -59,6 +59,7 @@ public class MapIndexFormulaTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@FailureExpectedWithNewMetamodel
|
||||||
@SuppressWarnings( {"unchecked", "UnnecessaryBoxing"})
|
@SuppressWarnings( {"unchecked", "UnnecessaryBoxing"})
|
||||||
public void testIndexFormulaMap() {
|
public void testIndexFormulaMap() {
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
|
@ -113,6 +114,7 @@ public class MapIndexFormulaTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@FailureExpectedWithNewMetamodel
|
||||||
@SuppressWarnings( {"unchecked"})
|
@SuppressWarnings( {"unchecked"})
|
||||||
public void testSQLQuery() {
|
public void testSQLQuery() {
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
|
|
|
@ -52,6 +52,10 @@ import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
public class ValueVisitorTest extends BaseUnitTestCase {
|
public class ValueVisitorTest extends BaseUnitTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testProperCallbacks() {
|
public void testProperCallbacks() {
|
||||||
|
if ( isMetadataUsed ) {
|
||||||
|
//doesn't mean anything for new metamodel
|
||||||
|
return;
|
||||||
|
}
|
||||||
final Mappings mappings = new Configuration().createMappings();
|
final Mappings mappings = new Configuration().createMappings();
|
||||||
final Table tbl = new Table();
|
final Table tbl = new Table();
|
||||||
final RootClass rootClass = new RootClass();
|
final RootClass rootClass = new RootClass();
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.junit.Test;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
|
import org.hibernate.metamodel.MetadataSources;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.testing.ServiceRegistryBuilder;
|
import org.hibernate.testing.ServiceRegistryBuilder;
|
||||||
import org.hibernate.testing.TestForIssue;
|
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
|
* Test for read-order independent resolution of user-defined types
|
||||||
* Testcase for issue HHH-7300
|
* Testcase for issue HHH-7300
|
||||||
|
*
|
||||||
* @author Stefan Schulze
|
* @author Stefan Schulze
|
||||||
*/
|
*/
|
||||||
@TestForIssue(jiraKey = "HHH-7300")
|
@TestForIssue(jiraKey = "HHH-7300")
|
||||||
public class UserTypeMappingTest extends BaseUnitTestCase{
|
public class UserTypeMappingTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
private Configuration cfg;
|
@Test
|
||||||
private ServiceRegistry serviceRegistry;
|
public void testFirstTypeThenEntity() {
|
||||||
|
assertMappings(
|
||||||
|
"org/hibernate/test/mapping/usertypes/TestEnumType.hbm.xml",
|
||||||
|
"org/hibernate/test/mapping/usertypes/TestEntity.hbm.xml"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Test
|
||||||
public void setup(){
|
public void testFirstEntityThenType() {
|
||||||
cfg=new Configuration();
|
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();
|
Properties p = new Properties();
|
||||||
p.put( Environment.DIALECT, "org.hibernate.dialect.HSQLDialect" );
|
p.put( Environment.DIALECT, "org.hibernate.dialect.HSQLDialect" );
|
||||||
p.put( "hibernate.connection.driver_class", "org.h2.Driver" );
|
p.put( "hibernate.connection.driver_class", "org.h2.Driver" );
|
||||||
p.put( "hibernate.connection.url", "jdbc:h2:mem:" );
|
p.put( "hibernate.connection.url", "jdbc:h2:mem:" );
|
||||||
p.put( "hibernate.connection.username", "sa" );
|
p.put( "hibernate.connection.username", "sa" );
|
||||||
p.put( "hibernate.connection.password", "" );
|
p.put( "hibernate.connection.password", "" );
|
||||||
cfg.setProperties(p);
|
cfg.setProperties( p );
|
||||||
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
|
ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
|
||||||
}
|
SessionFactory sessions = null;
|
||||||
|
try {
|
||||||
public void tearDown(){
|
if ( isMetadataUsed ) {
|
||||||
if(serviceRegistry!=null){
|
MetadataSources metadataSources = new MetadataSources( serviceRegistry );
|
||||||
ServiceRegistryBuilder.destroy( 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,9 @@ import org.hibernate.Transaction;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.mapping.Column;
|
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||||
import org.hibernate.mapping.ForeignKey;
|
import org.hibernate.metamodel.spi.relational.Column;
|
||||||
|
import org.hibernate.metamodel.spi.relational.ForeignKey;
|
||||||
import org.hibernate.metamodel.spi.relational.TableSpecification;
|
import org.hibernate.metamodel.spi.relational.TableSpecification;
|
||||||
import org.hibernate.test.util.SchemaUtil;
|
import org.hibernate.test.util.SchemaUtil;
|
||||||
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
||||||
|
@ -52,7 +53,6 @@ import static org.junit.Assert.assertTrue;
|
||||||
/**
|
/**
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
*/
|
*/
|
||||||
@FailureExpectedWithNewMetamodel
|
|
||||||
public class PropertyRefTest extends BaseCoreFunctionalTestCase {
|
public class PropertyRefTest extends BaseCoreFunctionalTestCase {
|
||||||
@Override
|
@Override
|
||||||
public String[] getMappings() {
|
public String[] getMappings() {
|
||||||
|
@ -111,6 +111,7 @@ public class PropertyRefTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@FailureExpectedWithNewMetamodel
|
||||||
public void testManyToManyPropertyRef() {
|
public void testManyToManyPropertyRef() {
|
||||||
// prepare some test data relating to the Group->Person many-to-many association
|
// prepare some test data relating to the Group->Person many-to-many association
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
|
@ -281,25 +282,25 @@ public class PropertyRefTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testForeignKeyCreation() {
|
public void testForeignKeyCreation() {
|
||||||
|
if ( !isMetadataUsed ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
TableSpecification table = SchemaUtil.getTable( Account.class, metadata() );
|
TableSpecification table = SchemaUtil.getTable( Account.class, metadata() );
|
||||||
|
EntityBinding personEntityBinding = getEntityBinding( Person.class );
|
||||||
Iterator foreignKeyIterator = table.getForeignKeys().iterator();
|
Iterator foreignKeyIterator = table.getForeignKeys().iterator();
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
while ( foreignKeyIterator.hasNext() ) {
|
while ( foreignKeyIterator.hasNext() ) {
|
||||||
ForeignKey element = (ForeignKey) foreignKeyIterator.next();
|
ForeignKey element = (ForeignKey) foreignKeyIterator.next();
|
||||||
if(element.getReferencedEntityName().equals(Person.class.getName() ) ) {
|
if ( element.getTargetTable().equals( personEntityBinding.getPrimaryTable() ) ) {
|
||||||
|
for ( Column column : element.getTargetColumns() ) {
|
||||||
if(!element.isReferenceToPrimaryKey() ) {
|
if ( column.getColumnName().getText( getDialect() ).equals( "person_userid" ) ) {
|
||||||
List referencedColumns = element.getReferencedColumns();
|
found = true;
|
||||||
Column column = (Column) referencedColumns.get(0);
|
|
||||||
if(column.getName().equals("person_userid") ) {
|
|
||||||
found = true; // extend test to include the columns
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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.Session;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.criterion.Restrictions;
|
import org.hibernate.criterion.Restrictions;
|
||||||
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -48,7 +47,6 @@ public class SubselectTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings( {"unchecked"})
|
@SuppressWarnings( {"unchecked"})
|
||||||
@FailureExpectedWithNewMetamodel
|
|
||||||
public void testEntitySubselect() {
|
public void testEntitySubselect() {
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Transaction t = s.beginTransaction();
|
Transaction t = s.beginTransaction();
|
||||||
|
@ -89,7 +87,6 @@ public class SubselectTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpectedWithNewMetamodel
|
|
||||||
public void testCustomColumnReadAndWrite() {
|
public void testCustomColumnReadAndWrite() {
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Transaction t = s.beginTransaction();
|
Transaction t = s.beginTransaction();
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
<class name="Person" table="PROPREF_PERS">
|
<class name="Person" table="PROPREF_PERS">
|
||||||
<id name="id">
|
<id name="id">
|
||||||
<generator class="hilo"/>
|
<generator class="seqhilo"/>
|
||||||
</id>
|
</id>
|
||||||
<property name="name" length="100"/>
|
<property name="name" length="100"/>
|
||||||
<property name="userId" column="person_userid" length="8" unique="true" not-null="true"/>
|
<property name="userId" column="person_userid" length="8" unique="true" not-null="true"/>
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
<class name="Address" table="PROPREF_ADDR">
|
<class name="Address" table="PROPREF_ADDR">
|
||||||
<id name="id">
|
<id name="id">
|
||||||
<generator class="hilo"/>
|
<generator class="seqhilo"/>
|
||||||
</id>
|
</id>
|
||||||
<property name="address" length="300"/>
|
<property name="address" length="300"/>
|
||||||
<property name="zip" length="5"/>
|
<property name="zip" length="5"/>
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
<id name="id" unsaved-value="0"
|
<id name="id" unsaved-value="0"
|
||||||
column="bid">
|
column="bid">
|
||||||
<generator class="hilo"/>
|
<generator class="seqhilo"/>
|
||||||
</id>
|
</id>
|
||||||
|
|
||||||
<property name="name"
|
<property name="name"
|
||||||
|
@ -49,7 +49,7 @@
|
||||||
|
|
||||||
<id name="id" unsaved-value="0"
|
<id name="id" unsaved-value="0"
|
||||||
column="bid">
|
column="bid">
|
||||||
<generator class="hilo"/>
|
<generator class="seqhilo"/>
|
||||||
</id>
|
</id>
|
||||||
|
|
||||||
<property name="identity"
|
<property name="identity"
|
||||||
|
|
|
@ -167,7 +167,7 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
|
||||||
}
|
}
|
||||||
this.entityManagerFactoryName = entityManagerFactoryName;
|
this.entityManagerFactoryName = entityManagerFactoryName;
|
||||||
if ( metadataImplementor != null ) {
|
if ( metadataImplementor != null ) {
|
||||||
applyNamedEntityGraphs( metadataImplementor.getNamedEntityGraphMap().values() );
|
applyNamedEntityGraphs( metadataImplementor.getNamedEntityGraphs().values() );
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityManagerFactoryRegistry.INSTANCE.addEntityManagerFactory( entityManagerFactoryName, this );
|
EntityManagerFactoryRegistry.INSTANCE.addEntityManagerFactory( entityManagerFactoryName, this );
|
||||||
|
|
|
@ -24,14 +24,14 @@ import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
|
||||||
*/
|
*/
|
||||||
public class BaseFunctionalTestCase extends BaseUnitTestCase {
|
public class BaseFunctionalTestCase extends BaseUnitTestCase {
|
||||||
public static final String VALIDATE_DATA_CLEANUP = "hibernate.test.validateDataCleanup";
|
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();
|
public static final Dialect DIALECT = Dialect.getDialect();
|
||||||
protected static final String[] NO_MAPPINGS = new String[0];
|
protected static final String[] NO_MAPPINGS = new String[0];
|
||||||
protected static final Class<?>[] NO_CLASSES = new Class[0];
|
protected static final Class<?>[] NO_CLASSES = new Class[0];
|
||||||
protected Configuration configuration;
|
protected Configuration configuration;
|
||||||
protected MetadataImplementor metadata;
|
protected MetadataImplementor metadata;
|
||||||
protected StandardServiceRegistryImpl serviceRegistry;
|
protected StandardServiceRegistryImpl serviceRegistry;
|
||||||
protected boolean isMetadataUsed;
|
|
||||||
|
|
||||||
protected static Dialect getDialect() {
|
protected static Dialect getDialect() {
|
||||||
return DIALECT;
|
return DIALECT;
|
||||||
|
@ -50,9 +50,7 @@ public class BaseFunctionalTestCase extends BaseUnitTestCase {
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isMetadataUsed() {
|
|
||||||
return isMetadataUsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------- services and service registry
|
//----------------------- services and service registry
|
||||||
protected BootstrapServiceRegistry buildBootstrapServiceRegistry() {
|
protected BootstrapServiceRegistry buildBootstrapServiceRegistry() {
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
|
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
|
||||||
import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
|
import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
|
||||||
|
import org.hibernate.metamodel.MetadataSources;
|
||||||
import org.hibernate.testing.jta.TestingJtaPlatformImpl;
|
import org.hibernate.testing.jta.TestingJtaPlatformImpl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,15 +45,18 @@ import org.hibernate.testing.jta.TestingJtaPlatformImpl;
|
||||||
@RunWith( CustomRunner.class )
|
@RunWith( CustomRunner.class )
|
||||||
public abstract class BaseUnitTestCase {
|
public abstract class BaseUnitTestCase {
|
||||||
private static final Logger log = Logger.getLogger( BaseUnitTestCase.class );
|
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
|
* 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.
|
* subclasses of {@link BaseSqlOutputTest} to fail.
|
||||||
*/
|
*/
|
||||||
protected static final String OUTPUT_PREFIX = SqlStatementLogger.OUTPUT_PREFIX;
|
protected static final String OUTPUT_PREFIX = SqlStatementLogger.OUTPUT_PREFIX;
|
||||||
|
protected static boolean isMetadataUsed = Boolean.valueOf( System.getProperty( USE_NEW_METADATA_MAPPINGS, "true" ) );
|
||||||
// @Rule
|
protected static boolean isMetadataUsed() {
|
||||||
// public TestRule globalTimeout = new Timeout( 30 * 60 * 1000 ); // no test should run longer than 30 minutes
|
return isMetadataUsed;
|
||||||
|
}
|
||||||
|
@Rule
|
||||||
|
public TestRule globalTimeout = new Timeout( 30 * 60 * 1000 ); // no test should run longer than 30 minutes
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void releaseTransactions() {
|
public void releaseTransactions() {
|
||||||
|
|
Loading…
Reference in New Issue