HHH-6354 component attribute natural id binding
This commit is contained in:
parent
473790c1e4
commit
1ab72cfdb6
|
@ -171,21 +171,22 @@ public class Binder {
|
||||||
private final MetadataImplementor metadata;
|
private final MetadataImplementor metadata;
|
||||||
private final IdentifierGeneratorFactory identifierGeneratorFactory;
|
private final IdentifierGeneratorFactory identifierGeneratorFactory;
|
||||||
private final ObjectNameNormalizer nameNormalizer;
|
private final ObjectNameNormalizer nameNormalizer;
|
||||||
private final HashMap< String, EntitySource > entitySourcesByName = new HashMap< String, EntitySource >();
|
private final HashMap<String, EntitySource> entitySourcesByName = new HashMap<String, EntitySource>();
|
||||||
private final HashMap< RootEntitySource, EntityHierarchy > entityHierarchiesByRootEntitySource =
|
private final HashMap<RootEntitySource, EntityHierarchy> entityHierarchiesByRootEntitySource =
|
||||||
new HashMap< RootEntitySource, EntityHierarchy >();
|
new HashMap<RootEntitySource, EntityHierarchy>();
|
||||||
private final HashMap< String, AttributeSource > attributeSourcesByName = new HashMap< String, AttributeSource >();
|
private final HashMap<String, AttributeSource> attributeSourcesByName = new HashMap<String, AttributeSource>();
|
||||||
private final LinkedList< LocalBindingContext > bindingContexts = new LinkedList< LocalBindingContext >();
|
private final LinkedList<LocalBindingContext> bindingContexts = new LinkedList<LocalBindingContext>();
|
||||||
private final LinkedList< InheritanceType > inheritanceTypes = new LinkedList< InheritanceType >();
|
private final LinkedList<InheritanceType> inheritanceTypes = new LinkedList<InheritanceType>();
|
||||||
|
|
||||||
private final LinkedList< EntityMode > entityModes = new LinkedList< EntityMode >();
|
private final LinkedList<EntityMode> entityModes = new LinkedList<EntityMode>();
|
||||||
|
|
||||||
private final HibernateTypeHelper typeHelper; // todo: refactor helper and remove redundant methods in this class
|
private final HibernateTypeHelper typeHelper; // todo: refactor helper and remove redundant methods in this class
|
||||||
|
|
||||||
public Binder( final MetadataImplementor metadata, final IdentifierGeneratorFactory identifierGeneratorFactory ) {
|
public Binder( final MetadataImplementor metadata, final IdentifierGeneratorFactory identifierGeneratorFactory ) {
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
this.identifierGeneratorFactory = identifierGeneratorFactory;
|
this.identifierGeneratorFactory = identifierGeneratorFactory;
|
||||||
nameNormalizer = new ObjectNameNormalizer() {
|
this.typeHelper = new HibernateTypeHelper( this, metadata );
|
||||||
|
this.nameNormalizer = new ObjectNameNormalizer() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NamingStrategy getNamingStrategy() {
|
protected NamingStrategy getNamingStrategy() {
|
||||||
|
@ -197,13 +198,12 @@ public class Binder {
|
||||||
return metadata.isGloballyQuotedIdentifiers();
|
return metadata.isGloballyQuotedIdentifiers();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
typeHelper = new HibernateTypeHelper( this, metadata );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private AttributeBinding attributeBinding( final String entityName, final String attributeName ) {
|
private AttributeBinding attributeBinding( final String entityName, final String attributeName ) {
|
||||||
// Check if binding has already been created
|
// Check if binding has already been created
|
||||||
EntityBinding entityBinding = entityBinding( entityName );
|
final EntityBinding entityBinding = entityBinding( entityName );
|
||||||
AttributeSource attributeSource = attributeSourcesByName.get( attributeSourcesByNameKey( entityName, attributeName ) );
|
final AttributeSource attributeSource = attributeSourcesByName.get( attributeSourcesByNameKey( entityName, attributeName ) );
|
||||||
bindAttribute( entityBinding, attributeSource );
|
bindAttribute( entityBinding, attributeSource );
|
||||||
return entityBinding.locateAttributeBinding( attributeName );
|
return entityBinding.locateAttributeBinding( attributeName );
|
||||||
}
|
}
|
||||||
|
@ -250,13 +250,13 @@ public class Binder {
|
||||||
case MANY_TO_ONE:
|
case MANY_TO_ONE:
|
||||||
return bindManyToOneAttribute(
|
return bindManyToOneAttribute(
|
||||||
attributeBindingContainer,
|
attributeBindingContainer,
|
||||||
(ToOneAttributeSource) attributeSource,
|
ToOneAttributeSource.class.cast( attributeSource ),
|
||||||
attribute
|
attribute
|
||||||
);
|
);
|
||||||
case COMPONENT:
|
case COMPONENT:
|
||||||
return bindComponentAttribute(
|
return bindComponentAttribute(
|
||||||
attributeBindingContainer,
|
attributeBindingContainer,
|
||||||
(ComponentAttributeSource) attributeSource,
|
ComponentAttributeSource.class.cast( attributeSource ),
|
||||||
attribute
|
attribute
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
|
@ -303,16 +303,14 @@ public class Binder {
|
||||||
final AttributeBindingContainer attributeBindingContainer,
|
final AttributeBindingContainer attributeBindingContainer,
|
||||||
final ComponentAttributeSource attributeSource,
|
final ComponentAttributeSource attributeSource,
|
||||||
SingularAttribute attribute ) {
|
SingularAttribute attribute ) {
|
||||||
Composite composite;
|
final Composite composite;
|
||||||
if ( attribute == null ) {
|
if ( attribute == null ) {
|
||||||
composite =
|
composite = new Composite(
|
||||||
new Composite(
|
|
||||||
attributeSource.getPath(),
|
attributeSource.getPath(),
|
||||||
attributeSource.getClassName(),
|
attributeSource.getClassName(),
|
||||||
attributeSource.getClassReference(),
|
attributeSource.getClassReference(),
|
||||||
null );
|
null );
|
||||||
attribute =
|
attribute = attributeBindingContainer.getAttributeContainer().createCompositeAttribute(
|
||||||
attributeBindingContainer.getAttributeContainer().createCompositeAttribute(
|
|
||||||
attributeSource.getName(),
|
attributeSource.getName(),
|
||||||
composite );
|
composite );
|
||||||
} else {
|
} else {
|
||||||
|
@ -325,6 +323,7 @@ public class Binder {
|
||||||
} else {
|
} else {
|
||||||
referencingAttribute = composite.createSingularAttribute( attributeSource.getParentReferenceAttributeName() );
|
referencingAttribute = composite.createSingularAttribute( attributeSource.getParentReferenceAttributeName() );
|
||||||
}
|
}
|
||||||
|
final SingularAttributeBinding.NaturalIdMutability naturalIdMutability = attributeSource.getNaturalIdMutability();
|
||||||
final CompositeAttributeBinding attributeBinding =
|
final CompositeAttributeBinding attributeBinding =
|
||||||
attributeBindingContainer.makeComponentAttributeBinding(
|
attributeBindingContainer.makeComponentAttributeBinding(
|
||||||
attribute,
|
attribute,
|
||||||
|
@ -332,7 +331,7 @@ public class Binder {
|
||||||
propertyAccessorName( attributeSource ),
|
propertyAccessorName( attributeSource ),
|
||||||
attributeSource.isIncludedInOptimisticLocking(),
|
attributeSource.isIncludedInOptimisticLocking(),
|
||||||
attributeSource.isLazy(),
|
attributeSource.isLazy(),
|
||||||
attributeSource.getNaturalIdMutability(),
|
naturalIdMutability,
|
||||||
createMetaAttributeContext( attributeBindingContainer, attributeSource ) );
|
createMetaAttributeContext( attributeBindingContainer, attributeSource ) );
|
||||||
bindAttributes( attributeBinding, attributeSource );
|
bindAttributes( attributeBinding, attributeSource );
|
||||||
return attributeBinding;
|
return attributeBinding;
|
||||||
|
@ -346,7 +345,7 @@ public class Binder {
|
||||||
attribute = createSingularAttribute( attributeBindingContainer, attributeSource );
|
attribute = createSingularAttribute( attributeBindingContainer, attributeSource );
|
||||||
}
|
}
|
||||||
// TODO: figure out which table is used (could be secondary table...)
|
// TODO: figure out which table is used (could be secondary table...)
|
||||||
TableSpecification table = attributeBindingContainer.seekEntityBinding().getPrimaryTable();
|
final TableSpecification table = attributeBindingContainer.seekEntityBinding().getPrimaryTable();
|
||||||
final List< RelationalValueBinding > relationalValueBindings =
|
final List< RelationalValueBinding > relationalValueBindings =
|
||||||
bindValues( attributeBindingContainer, attributeSource, attribute, table );
|
bindValues( attributeBindingContainer, attributeSource, attribute, table );
|
||||||
|
|
||||||
|
@ -936,7 +935,6 @@ public class Binder {
|
||||||
bindingContexts.peek().getMappingDefaults().getDiscriminatorColumnName(),
|
bindingContexts.peek().getMappingDefaults().getDiscriminatorColumnName(),
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
|
||||||
false );
|
false );
|
||||||
} else {
|
} else {
|
||||||
value = table.locateOrCreateDerivedValue( ( ( DerivedValueSource ) valueSource ).getExpression() );
|
value = table.locateOrCreateDerivedValue( ( ( DerivedValueSource ) valueSource ).getExpression() );
|
||||||
|
@ -995,7 +993,6 @@ public class Binder {
|
||||||
bindingContexts.peek().getMappingDefaults().getDiscriminatorColumnName(),
|
bindingContexts.peek().getMappingDefaults().getDiscriminatorColumnName(),
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1459,7 +1456,7 @@ public class Binder {
|
||||||
|
|
||||||
private void bindUniqueConstraints( final EntityBinding entityBinding, final EntitySource entitySource ) {
|
private void bindUniqueConstraints( final EntityBinding entityBinding, final EntitySource entitySource ) {
|
||||||
for ( final ConstraintSource constraintSource : entitySource.getConstraints() ) {
|
for ( final ConstraintSource constraintSource : entitySource.getConstraints() ) {
|
||||||
if ( constraintSource instanceof UniqueConstraintSource ) {
|
if ( UniqueConstraintSource.class.isInstance( constraintSource ) ) {
|
||||||
final TableSpecification table = entityBinding.locateTable( constraintSource.getTableName() );
|
final TableSpecification table = entityBinding.locateTable( constraintSource.getTableName() );
|
||||||
final String constraintName = constraintSource.name();
|
final String constraintName = constraintSource.name();
|
||||||
if ( constraintName == null ) {
|
if ( constraintName == null ) {
|
||||||
|
@ -1484,14 +1481,17 @@ public class Binder {
|
||||||
) ? SingularAttributeSource.class.cast( valueSourceContainer ).getNaturalIdMutability()
|
) ? SingularAttributeSource.class.cast( valueSourceContainer ).getNaturalIdMutability()
|
||||||
: SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID;
|
: SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID;
|
||||||
final boolean isNaturalId = naturalIdMutability != SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID;
|
final boolean isNaturalId = naturalIdMutability != SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID;
|
||||||
final boolean isImmutable = isNaturalId && (naturalIdMutability == SingularAttributeBinding.NaturalIdMutability.IMMUTABLE);
|
final boolean isImmutableNaturalId = isNaturalId && (naturalIdMutability == SingularAttributeBinding.NaturalIdMutability.IMMUTABLE);
|
||||||
|
|
||||||
if ( valueSourceContainer.relationalValueSources().isEmpty() ) {
|
if ( valueSourceContainer.relationalValueSources().isEmpty() ) {
|
||||||
final String columnName =
|
final String columnName =
|
||||||
quotedIdentifier( bindingContexts.peek().getNamingStrategy().propertyToColumnName( attribute.getName() ) );
|
quotedIdentifier( bindingContexts.peek().getNamingStrategy().propertyToColumnName( attribute.getName() ) );
|
||||||
final Column column = defaultTable.locateOrCreateColumn( columnName );
|
final Column column = defaultTable.locateOrCreateColumn( columnName );
|
||||||
column.setNullable( !isNaturalId && valueSourceContainer.areValuesNullableByDefault() );
|
column.setNullable( !isNaturalId && valueSourceContainer.areValuesNullableByDefault() );
|
||||||
column.setUnique( isNaturalId );
|
if(isNaturalId){
|
||||||
valueBindings.add( new RelationalValueBinding( column, true, !isImmutable ) );
|
addUniqueConstraintForNaturalIdColumn( defaultTable, column );
|
||||||
|
}
|
||||||
|
valueBindings.add( new RelationalValueBinding( column, true, !isImmutableNaturalId ) );
|
||||||
} else {
|
} else {
|
||||||
final String name = attribute.getName();
|
final String name = attribute.getName();
|
||||||
for ( final RelationalValueSource valueSource : valueSourceContainer.relationalValueSources() ) {
|
for ( final RelationalValueSource valueSource : valueSourceContainer.relationalValueSources() ) {
|
||||||
|
@ -1509,15 +1509,11 @@ public class Binder {
|
||||||
toBoolean(
|
toBoolean(
|
||||||
columnSource.isIncludedInUpdate(),
|
columnSource.isIncludedInUpdate(),
|
||||||
valueSourceContainer.areValuesIncludedInUpdateByDefault() );
|
valueSourceContainer.areValuesIncludedInUpdateByDefault() );
|
||||||
|
Column column = createColumn( table, columnSource, name, isNaturalId, valueSourceContainer.areValuesNullableByDefault(), true );
|
||||||
valueBindings.add( new RelationalValueBinding( createColumn(
|
if(isNaturalId){
|
||||||
table,
|
addUniqueConstraintForNaturalIdColumn( table, column );
|
||||||
columnSource,
|
}
|
||||||
name,
|
valueBindings.add( new RelationalValueBinding( column, isIncludedInInsert, !isImmutableNaturalId && isIncludedInUpdate ) );
|
||||||
isNaturalId,
|
|
||||||
isNaturalId,
|
|
||||||
valueSourceContainer.areValuesNullableByDefault(),
|
|
||||||
true ), isIncludedInInsert, !isImmutable && isIncludedInUpdate ) );
|
|
||||||
} else {
|
} else {
|
||||||
final DerivedValue derivedValue =
|
final DerivedValue derivedValue =
|
||||||
table.locateOrCreateDerivedValue( ( ( DerivedValueSource ) valueSource ).getExpression() );
|
table.locateOrCreateDerivedValue( ( ( DerivedValueSource ) valueSource ).getExpression() );
|
||||||
|
@ -1528,6 +1524,11 @@ public class Binder {
|
||||||
return valueBindings;
|
return valueBindings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addUniqueConstraintForNaturalIdColumn(final TableSpecification table, final Column column) {
|
||||||
|
final UniqueKey uniqueKey = table.getOrCreateUniqueKey( "natural_id_unique_key_" );
|
||||||
|
uniqueKey.addColumn( column );
|
||||||
|
}
|
||||||
|
|
||||||
private void bindVersion( final EntityBinding rootEntityBinding, final VersionAttributeSource versionAttributeSource ) {
|
private void bindVersion( final EntityBinding rootEntityBinding, final VersionAttributeSource versionAttributeSource ) {
|
||||||
if ( versionAttributeSource == null ) {
|
if ( versionAttributeSource == null ) {
|
||||||
return;
|
return;
|
||||||
|
@ -1575,7 +1576,6 @@ public class Binder {
|
||||||
final ColumnSource columnSource,
|
final ColumnSource columnSource,
|
||||||
final String defaultName,
|
final String defaultName,
|
||||||
final boolean forceNotNull,
|
final boolean forceNotNull,
|
||||||
final boolean forceUnique,
|
|
||||||
final boolean isNullableByDefault,
|
final boolean isNullableByDefault,
|
||||||
final boolean isDefaultAttributeName ) {
|
final boolean isDefaultAttributeName ) {
|
||||||
if ( columnSource.getName() == null && defaultName == null ) {
|
if ( columnSource.getName() == null && defaultName == null ) {
|
||||||
|
@ -1608,7 +1608,7 @@ public class Binder {
|
||||||
column.setJdbcDataType( columnSource.getDatatype() );
|
column.setJdbcDataType( columnSource.getDatatype() );
|
||||||
column.setReadFragment( columnSource.getReadFragment() );
|
column.setReadFragment( columnSource.getReadFragment() );
|
||||||
column.setWriteFragment( columnSource.getWriteFragment() );
|
column.setWriteFragment( columnSource.getWriteFragment() );
|
||||||
column.setUnique( forceUnique || columnSource.isUnique() );
|
column.setUnique( columnSource.isUnique() );
|
||||||
column.setCheckCondition( columnSource.getCheckCondition() );
|
column.setCheckCondition( columnSource.getCheckCondition() );
|
||||||
column.setComment( columnSource.getComment() );
|
column.setComment( columnSource.getComment() );
|
||||||
return column;
|
return column;
|
||||||
|
|
|
@ -85,7 +85,7 @@ public abstract class MappedAttribute implements Comparable<MappedAttribute> {
|
||||||
/**
|
/**
|
||||||
* Is this property a natural id property and what's the mutability it is.
|
* Is this property a natural id property and what's the mutability it is.
|
||||||
*/
|
*/
|
||||||
private final SingularAttributeBinding.NaturalIdMutability naturalIdMutability;
|
private SingularAttributeBinding.NaturalIdMutability naturalIdMutability;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether a change of the property's value triggers a version increment of the entity (in case of optimistic
|
* Whether a change of the property's value triggers a version increment of the entity (in case of optimistic
|
||||||
|
@ -164,6 +164,10 @@ public abstract class MappedAttribute implements Comparable<MappedAttribute> {
|
||||||
return naturalIdMutability;
|
return naturalIdMutability;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setNaturalIdMutability(SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
|
||||||
|
this.naturalIdMutability = naturalIdMutability;
|
||||||
|
}
|
||||||
|
|
||||||
public AttributeNature getAttributeNature() {
|
public AttributeNature getAttributeNature() {
|
||||||
return attributeNature;
|
return attributeNature;
|
||||||
}
|
}
|
||||||
|
@ -281,6 +285,8 @@ public abstract class MappedAttribute implements Comparable<MappedAttribute> {
|
||||||
}
|
}
|
||||||
return checkCondition;
|
return checkCondition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -122,9 +122,11 @@ public class ComponentAttributeSourceImpl implements ComponentAttributeSource {
|
||||||
if ( attributeOverrides.containsKey( tmp ) ) {
|
if ( attributeOverrides.containsKey( tmp ) ) {
|
||||||
attributeOverride = attributeOverrides.get( tmp );
|
attributeOverride = attributeOverrides.get( tmp );
|
||||||
}
|
}
|
||||||
|
attribute.setNaturalIdMutability( embeddableClass.getNaturalIdMutability() );
|
||||||
attributeList.add( new SingularAttributeSourceImpl( attribute, attributeOverride ) );
|
attributeList.add( new SingularAttributeSourceImpl( attribute, attributeOverride ) );
|
||||||
}
|
}
|
||||||
for ( EmbeddableClass embeddable : embeddableClass.getEmbeddedClasses().values() ) {
|
for ( EmbeddableClass embeddable : embeddableClass.getEmbeddedClasses().values() ) {
|
||||||
|
embeddable.setNaturalIdMutability( embeddableClass.getNaturalIdMutability() );
|
||||||
attributeList.add(
|
attributeList.add(
|
||||||
new ComponentAttributeSourceImpl(
|
new ComponentAttributeSourceImpl(
|
||||||
embeddable,
|
embeddable,
|
||||||
|
@ -134,6 +136,7 @@ public class ComponentAttributeSourceImpl implements ComponentAttributeSource {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for ( AssociationAttribute associationAttribute : embeddableClass.getAssociationAttributes() ) {
|
for ( AssociationAttribute associationAttribute : embeddableClass.getAssociationAttributes() ) {
|
||||||
|
associationAttribute.setNaturalIdMutability( embeddableClass.getNaturalIdMutability() );
|
||||||
attributeList.add( new ToOneAttributeSourceImpl( associationAttribute ) );
|
attributeList.add( new ToOneAttributeSourceImpl( associationAttribute ) );
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableList( attributeList );
|
return Collections.unmodifiableList( attributeList );
|
||||||
|
|
|
@ -41,7 +41,7 @@ import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
||||||
public class EmbeddableClass extends ConfiguredClass {
|
public class EmbeddableClass extends ConfiguredClass {
|
||||||
private final String embeddedAttributeName;
|
private final String embeddedAttributeName;
|
||||||
private final String parentReferencingAttributeName;
|
private final String parentReferencingAttributeName;
|
||||||
private final SingularAttributeBinding.NaturalIdMutability naturalIdMutability;
|
private SingularAttributeBinding.NaturalIdMutability naturalIdMutability;
|
||||||
|
|
||||||
public EmbeddableClass(
|
public EmbeddableClass(
|
||||||
ClassInfo classInfo,
|
ClassInfo classInfo,
|
||||||
|
@ -75,6 +75,10 @@ public class EmbeddableClass extends ConfiguredClass {
|
||||||
public SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability() {
|
public SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability() {
|
||||||
return naturalIdMutability;
|
return naturalIdMutability;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setNaturalIdMutability(SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
|
||||||
|
this.naturalIdMutability = naturalIdMutability;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -67,8 +67,7 @@ public class EntityBindingContext implements LocalBindingContext, AnnotationBind
|
||||||
public EntityBindingContext(AnnotationBindingContext contextDelegate, ConfiguredClass source) {
|
public EntityBindingContext(AnnotationBindingContext contextDelegate, ConfiguredClass source) {
|
||||||
this.contextDelegate = contextDelegate;
|
this.contextDelegate = contextDelegate;
|
||||||
this.origin = new Origin( SourceType.ANNOTATION, source.getName() );
|
this.origin = new Origin( SourceType.ANNOTATION, source.getName() );
|
||||||
|
this.localIdentifierGeneratorDefinitionMap = processLocalIdentifierGeneratorDefinitions( source.getClassInfo() );
|
||||||
localIdentifierGeneratorDefinitionMap = processLocalIdentifierGeneratorDefinitions( source.getClassInfo() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String,IdGenerator> processLocalIdentifierGeneratorDefinitions(final ClassInfo classInfo) {
|
private Map<String,IdGenerator> processLocalIdentifierGeneratorDefinitions(final ClassInfo classInfo) {
|
||||||
|
@ -217,7 +216,7 @@ public class EntityBindingContext implements LocalBindingContext, AnnotationBind
|
||||||
public IdGenerator findIdGenerator(String name) {
|
public IdGenerator findIdGenerator(String name) {
|
||||||
IdGenerator definition = localIdentifierGeneratorDefinitionMap.get( name );
|
IdGenerator definition = localIdentifierGeneratorDefinitionMap.get( name );
|
||||||
if ( definition == null ) {
|
if ( definition == null ) {
|
||||||
contextDelegate.findIdGenerator( name );
|
definition= contextDelegate.findIdGenerator( name );
|
||||||
}
|
}
|
||||||
return definition;
|
return definition;
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,17 +131,13 @@ public class EntityClass extends ConfiguredClass {
|
||||||
super( classInfo, hierarchyAccessType, parent, context );
|
super( classInfo, hierarchyAccessType, parent, context );
|
||||||
this.inheritanceType = inheritanceType;
|
this.inheritanceType = inheritanceType;
|
||||||
this.idType = determineIdType();
|
this.idType = determineIdType();
|
||||||
boolean hasOwnTable = definesItsOwnTable();
|
|
||||||
|
final boolean hasOwnTable = definesItsOwnTable();
|
||||||
|
|
||||||
this.explicitEntityName = determineExplicitEntityName();
|
this.explicitEntityName = determineExplicitEntityName();
|
||||||
|
|
||||||
this.constraintSources = new HashSet<ConstraintSource>();
|
this.constraintSources = new HashSet<ConstraintSource>();
|
||||||
|
this.primaryTableSource = hasOwnTable ? createPrimaryTableSource() : null;
|
||||||
if ( hasOwnTable ) {
|
|
||||||
this.primaryTableSource = createPrimaryTableSource();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.primaryTableSource = null;
|
|
||||||
}
|
|
||||||
this.secondaryTableSources = createSecondaryTableSources();
|
this.secondaryTableSources = createSecondaryTableSources();
|
||||||
|
|
||||||
this.customLoaderQueryName = determineCustomLoader();
|
this.customLoaderQueryName = determineCustomLoader();
|
||||||
|
@ -213,12 +209,7 @@ public class EntityClass extends ConfiguredClass {
|
||||||
|
|
||||||
public TableSpecificationSource getPrimaryTableSource() {
|
public TableSpecificationSource getPrimaryTableSource() {
|
||||||
// todo : this is different from hbm which returns null if "!definesItsOwnTable()"
|
// todo : this is different from hbm which returns null if "!definesItsOwnTable()"
|
||||||
if ( definesItsOwnTable() ) {
|
return definesItsOwnTable() ? primaryTableSource : ( (EntityClass) getParent() ).getPrimaryTableSource();
|
||||||
return primaryTableSource;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return ( (EntityClass) getParent() ).getPrimaryTableSource();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<SecondaryTableSource> getSecondaryTableSources() {
|
public Set<SecondaryTableSource> getSecondaryTableSources() {
|
||||||
|
@ -669,16 +660,16 @@ public class EntityClass extends ConfiguredClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createUniqueConstraints(AnnotationInstance tableAnnotation, String tableName) {
|
private void createUniqueConstraints(AnnotationInstance tableAnnotation, String tableName) {
|
||||||
AnnotationValue value = tableAnnotation.value( "uniqueConstraints" );
|
final AnnotationValue value = tableAnnotation.value( "uniqueConstraints" );
|
||||||
if ( value == null ) {
|
if ( value == null ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AnnotationInstance[] uniqueConstraints = value.asNestedArray();
|
final AnnotationInstance[] uniqueConstraints = value.asNestedArray();
|
||||||
for ( AnnotationInstance unique : uniqueConstraints ) {
|
for ( final AnnotationInstance unique : uniqueConstraints ) {
|
||||||
String name = unique.value( "name" ) == null ? null : unique.value( "name" ).asString();
|
final String name = unique.value( "name" ) == null ? null : unique.value( "name" ).asString();
|
||||||
String[] columnNames = unique.value( "columnNames" ).asStringArray();
|
final String[] columnNames = unique.value( "columnNames" ).asStringArray();
|
||||||
UniqueConstraintSourceImpl uniqueConstraintSource =
|
final UniqueConstraintSourceImpl uniqueConstraintSource =
|
||||||
new UniqueConstraintSourceImpl(
|
new UniqueConstraintSourceImpl(
|
||||||
name, tableName, Arrays.asList( columnNames )
|
name, tableName, Arrays.asList( columnNames )
|
||||||
);
|
);
|
||||||
|
@ -827,12 +818,7 @@ public class EntityClass extends ConfiguredClass {
|
||||||
|| hibernateProxyAnnotation.value( "lazy" ).asBoolean();
|
|| hibernateProxyAnnotation.value( "lazy" ).asBoolean();
|
||||||
if ( isLazy ) {
|
if ( isLazy ) {
|
||||||
final AnnotationValue proxyClassValue = hibernateProxyAnnotation.value( "proxyClass" );
|
final AnnotationValue proxyClassValue = hibernateProxyAnnotation.value( "proxyClass" );
|
||||||
if ( proxyClassValue == null ) {
|
proxy = proxyClassValue == null? getName() : proxyClassValue.asString();
|
||||||
proxy = getName();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
proxy = proxyClassValue.asString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
proxy = null;
|
proxy = null;
|
||||||
|
|
|
@ -193,12 +193,12 @@ public class CompositeAttributeBinding
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AttributeBinding locateAttributeBinding(List<org.hibernate.metamodel.spi.relational.Value> values) {
|
public AttributeBinding locateAttributeBinding(List<org.hibernate.metamodel.spi.relational.Value> values) {
|
||||||
for(AttributeBinding attributeBinding : attributeBindingMap.values()) {
|
for ( final AttributeBinding attributeBinding : attributeBindingMap.values() ) {
|
||||||
if(!(attributeBinding instanceof BasicAttributeBinding)) {
|
if ( !BasicAttributeBinding.class.isInstance( attributeBinding ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
BasicAttributeBinding basicAttributeBinding = (BasicAttributeBinding) attributeBinding;
|
final BasicAttributeBinding basicAttributeBinding = (BasicAttributeBinding) attributeBinding;
|
||||||
if(basicAttributeBinding.getRelationalValueBindings().equals( values )) {
|
if ( basicAttributeBinding.getRelationalValueBindings().equals( values ) ) {
|
||||||
return attributeBinding;
|
return attributeBinding;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class RelationalValueBinding {
|
||||||
private final boolean isDerived;
|
private final boolean isDerived;
|
||||||
private final boolean isNullable;
|
private final boolean isNullable;
|
||||||
|
|
||||||
public RelationalValueBinding(DerivedValue value) {
|
public RelationalValueBinding(final DerivedValue value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.includeInInsert = false;
|
this.includeInInsert = false;
|
||||||
this.includeInUpdate = false;
|
this.includeInUpdate = false;
|
||||||
|
@ -51,7 +51,7 @@ public class RelationalValueBinding {
|
||||||
this.isNullable = true;
|
this.isNullable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RelationalValueBinding(Column value, boolean includeInInsert, boolean includeInUpdate) {
|
public RelationalValueBinding(final Column value, final boolean includeInInsert, final boolean includeInUpdate) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.includeInInsert = includeInInsert;
|
this.includeInInsert = includeInInsert;
|
||||||
this.includeInUpdate = includeInUpdate;
|
this.includeInUpdate = includeInUpdate;
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class Building {
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@NaturalId
|
@NaturalId
|
||||||
private String address;
|
private String address;
|
||||||
@NaturalId
|
@NaturalId
|
||||||
|
@ -138,5 +138,5 @@ public class Building {
|
||||||
return "Building [id=" + id + ", name=" + name + ", address=" + address + ", city=" + city + ", state=" + state
|
return "Building [id=" + id + ", name=" + name + ", address=" + address + ", city=" + city + ", state=" + state
|
||||||
+ "]";
|
+ "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue