Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,10 @@ public void setJoins(Map<String, Join> joins) {
}

public Join getJoin() {
final AnnotatedColumn firstColumn = columns.get( 0 );
final var firstColumn = columns.get( 0 );
final String explicitTableName = firstColumn.getExplicitTableName();
//note: checkPropertyConsistency() is responsible for ensuring they all have the same table name
Join join = joins.get( explicitTableName );
if ( join == null ) {
// annotation binding seems to use logical and physical naming somewhat inconsistently...
final String physicalTableName = getBuildingContext().getMetadataCollector()
.getPhysicalTableName( explicitTableName );
if ( physicalTableName != null ) {
join = joins.get( physicalTableName );
}
}
final var join = getJoin( explicitTableName );
if ( join == null ) {
throw new AnnotationException(
"Secondary table '" + explicitTableName + "' for property '" + propertyName + "' of entity'" + getPropertyHolder().getClassName()
Expand All @@ -106,8 +98,22 @@ public Join getJoin() {
}
}

private Join getJoin(String explicitTableName) {
final var join = joins.get( explicitTableName );
if ( join != null ) {
return join;
}
else {
// annotation binding seems to use logical and physical naming somewhat inconsistently...
final String physicalTableName =
getBuildingContext().getMetadataCollector()
.getPhysicalTableName( explicitTableName );
return physicalTableName != null ? joins.get( physicalTableName ) : null;
}
}

public boolean isSecondary() {
final AnnotatedColumn firstColumn = columns.get( 0 );
final var firstColumn = columns.get( 0 );
final String explicitTableName = firstColumn.getExplicitTableName();
//note: checkPropertyConsistency() is responsible for ensuring they all have the same table name
return isNotEmpty( explicitTableName )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,16 @@

import jakarta.persistence.JoinColumn;

import static org.hibernate.boot.model.internal.AnnotatedJoinColumn.buildExplicitJoinTableJoinColumn;
import static org.hibernate.boot.model.internal.AnnotatedJoinColumn.buildImplicitJoinTableJoinColumn;
import static org.hibernate.boot.model.internal.AnnotatedJoinColumn.buildJoinColumn;
import static org.hibernate.boot.model.internal.BinderHelper.findReferencedColumnOwner;
import static org.hibernate.boot.model.internal.BinderHelper.getRelativePath;
import static org.hibernate.boot.model.internal.ForeignKeyType.EXPLICIT_PRIMARY_KEY_REFERENCE;
import static org.hibernate.boot.model.internal.ForeignKeyType.NON_PRIMARY_KEY_REFERENCE;
import static org.hibernate.boot.model.naming.ImplicitJoinColumnNameSource.Nature.ELEMENT_COLLECTION;
import static org.hibernate.boot.model.naming.ImplicitJoinColumnNameSource.Nature.ENTITY;
import static org.hibernate.boot.model.naming.ImplicitJoinColumnNameSource.Nature.ENTITY_COLLECTION;
import static org.hibernate.internal.util.StringHelper.isBlank;
import static org.hibernate.internal.util.StringHelper.isNotBlank;
import static org.hibernate.internal.util.StringHelper.isQuoted;
Expand Down Expand Up @@ -94,7 +102,7 @@ public static AnnotatedJoinColumns buildJoinColumnsOrFormulas(
AnnotatedJoinColumn.buildJoinFormula( formula, parent );
}
else {
AnnotatedJoinColumn.buildJoinColumn( column, mappedBy, parent, propertyHolder, inferredData );
buildJoinColumn( column, mappedBy, parent, propertyHolder, inferredData );
}
}

Expand Down Expand Up @@ -169,7 +177,7 @@ public static AnnotatedJoinColumns buildJoinColumnsWithDefaultColumnSuffix(
parent.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
parent.setMappedBy( mappedBy );
if ( isEmpty( actualColumns ) ) {
AnnotatedJoinColumn.buildJoinColumn(
buildJoinColumn(
null,
mappedBy,
parent,
Expand All @@ -181,7 +189,7 @@ public static AnnotatedJoinColumns buildJoinColumnsWithDefaultColumnSuffix(
else {
parent.setMappedBy( mappedBy );
for ( var actualColumn : actualColumns ) {
AnnotatedJoinColumn.buildJoinColumn(
buildJoinColumn(
actualColumn,
mappedBy,
parent,
Expand Down Expand Up @@ -212,11 +220,11 @@ public static AnnotatedJoinColumns buildJoinTableJoinColumns(
parent.setPropertyName( getRelativePath( propertyHolder, inferredData.getPropertyName() ) );
parent.setMappedBy( mappedBy );
if ( joinColumns == null ) {
AnnotatedJoinColumn.buildImplicitJoinTableJoinColumn( parent, propertyHolder, inferredData );
buildImplicitJoinTableJoinColumn( parent, propertyHolder, inferredData );
}
else {
for ( var joinColumn : joinColumns ) {
AnnotatedJoinColumn.buildExplicitJoinTableJoinColumn( parent, propertyHolder, inferredData, joinColumn );
buildExplicitJoinTableJoinColumn( parent, propertyHolder, inferredData, joinColumn );
}
}
handlePropertyRef( inferredData.getAttributeMember(), parent );
Expand All @@ -228,11 +236,11 @@ Property resolveMapsId() {
final var identifier = persistentClass.getIdentifier();
try {
return identifier instanceof Component embeddedIdType
? embeddedIdType.getProperty( getMapsId() ) // an @EmbeddedId
: persistentClass.getProperty( getMapsId() ); // a simple id or an @IdClass
? embeddedIdType.getProperty( mapsId ) // an @EmbeddedId
: persistentClass.getProperty( mapsId ); // a simple id or an @IdClass
}
catch (MappingException me) {
throw new AnnotationException( "Identifier field '" + getMapsId()
throw new AnnotationException( "Identifier field '" + mapsId
+ "' named in '@MapsId' does not exist in entity '" + persistentClass.getEntityName() + "'",
me );
}
Expand Down Expand Up @@ -318,7 +326,7 @@ public void setMappedBy(String entityName, String logicalTableName, String mappe
*/
public ForeignKeyType getReferencedColumnsType(PersistentClass referencedEntity) {
if ( referencedProperty != null ) {
return ForeignKeyType.NON_PRIMARY_KEY_REFERENCE;
return NON_PRIMARY_KEY_REFERENCE;
}

if ( columns.isEmpty() ) {
Expand All @@ -341,7 +349,7 @@ public ForeignKeyType getReferencedColumnsType(PersistentClass referencedEntity)
throw new FailedSecondPassException( me.getMessage(), me );
}
}
final Table table = table( columnOwner );
final var table = table( columnOwner );
// final List<Selectable> keyColumns = referencedEntity.getKey().getSelectables();
final var keyColumns =
table.getPrimaryKey() == null
Expand All @@ -353,17 +361,17 @@ public ForeignKeyType getReferencedColumnsType(PersistentClass referencedEntity)
explicitColumnReference = true;
if ( !keyColumns.contains( column( context, table, column.getReferencedColumn() ) ) ) {
// we have a column which does not belong to the PK
return ForeignKeyType.NON_PRIMARY_KEY_REFERENCE;
return NON_PRIMARY_KEY_REFERENCE;
}
}
}
if ( explicitColumnReference ) {
// if we got to here, all the columns belong to the PK
return keyColumns.size() == columns.size()
// we have all the PK columns
? ForeignKeyType.EXPLICIT_PRIMARY_KEY_REFERENCE
? EXPLICIT_PRIMARY_KEY_REFERENCE
// we have a subset of the PK columns
: ForeignKeyType.NON_PRIMARY_KEY_REFERENCE;
: NON_PRIMARY_KEY_REFERENCE;
}
else {
// there were no nonempty referencedColumnNames
Expand Down Expand Up @@ -395,8 +403,9 @@ private static Column column(MetadataBuildingContext context, Table table, Strin
}

String buildDefaultColumnName(PersistentClass referencedEntity, String logicalReferencedColumn) {
final var options = getBuildingContext().getBuildingOptions();
final var collector = getBuildingContext().getMetadataCollector();
final var context = getBuildingContext();
final var options = context.getBuildingOptions();
final var collector = context.getMetadataCollector();
final var database = collector.getDatabase();
final var jdbcEnvironment = database.getJdbcEnvironment();
final Identifier columnIdentifier = columnIdentifier(
Expand Down Expand Up @@ -464,9 +473,10 @@ public Identifier getReferencedPrimaryKeyColumnName() {

private Identifier handleElement(Identifier columnIdentifier) {
// HHH-11826 magic. See AnnotatedColumn and the HHH-6005 comments
if ( columnIdentifier.getText().contains( "_{element}_" ) ) {
final String identifierText = columnIdentifier.getText();
if ( identifierText.contains( "_{element}_" ) ) {
return Identifier.toIdentifier(
columnIdentifier.getText().replace( "_{element}_", "_" ),
identifierText.replace( "_{element}_", "_" ),
columnIdentifier.isQuoted()
);
}
Expand Down Expand Up @@ -502,13 +512,13 @@ private boolean isMappedBySide() {

private ImplicitJoinColumnNameSource.Nature getImplicitNature() {
if ( getPropertyHolder().isEntity() ) {
return ImplicitJoinColumnNameSource.Nature.ENTITY;
return ENTITY;
}
else if ( isElementCollection() ) {
return ImplicitJoinColumnNameSource.Nature.ELEMENT_COLLECTION;
return ELEMENT_COLLECTION;
}
else {
return ImplicitJoinColumnNameSource.Nature.ENTITY_COLLECTION;
return ENTITY_COLLECTION;
}
}

Expand Down Expand Up @@ -589,7 +599,7 @@ public Identifier getReferencedColumnName() {
return null;
}

final Property mappedByProperty =
final var mappedByProperty =
collector.getEntityBinding( getMappedByEntityName() )
.getProperty( getMappedByPropertyName() );
final var value = (SimpleValue) mappedByProperty.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,15 @@ public static void bindDefaults(MetadataBuildingContext context) {
final var definitionBuilder = new IdentifierGeneratorDefinition.Builder();
interpretSequenceGenerator( generatorRegistration.configuration(), definitionBuilder );
final var idGenDef = definitionBuilder.build();
if ( BOOT_LOGGER.isTraceEnabled() ) {
BOOT_LOGGER.addingGlobalSequenceGenerator( name );
}
BOOT_LOGGER.addingGlobalSequenceGenerator( name );
metadataCollector.addDefaultIdentifierGenerator( idGenDef );
} );

globalRegistrations.getTableGeneratorRegistrations().forEach( (name, generatorRegistration) -> {
final var definitionBuilder = new IdentifierGeneratorDefinition.Builder();
interpretTableGenerator( generatorRegistration.configuration(), definitionBuilder );
final var idGenDef = definitionBuilder.build();
if ( BOOT_LOGGER.isTraceEnabled() ) {
BOOT_LOGGER.addingGlobalTableGenerator( name );
}
BOOT_LOGGER.addingGlobalTableGenerator( name );
metadataCollector.addDefaultIdentifierGenerator( idGenDef );
} );

Expand Down Expand Up @@ -277,7 +273,6 @@ private static void bindTypeDescriptorRegistrations(
AnnotationTarget annotatedElement,
MetadataBuildingContext context) {
final var managedBeanRegistry = context.getBootstrapContext().getManagedBeanRegistry();

final var sourceModelContext = modelsContext( context );

annotatedElement.forEachAnnotationUsage( JavaTypeRegistration.class, sourceModelContext, (usage) -> {
Expand Down Expand Up @@ -422,9 +417,8 @@ private static void bindFetchProfile(FetchProfile fetchProfile, MetadataBuilding
final String name = fetchProfile.name();
if ( reuseOrCreateFetchProfile( context, name ) ) {
for ( var fetchOverride : fetchProfile.fetchOverrides() ) {
final FetchType fetchType = fetchOverride.fetch();
final FetchMode fetchMode = fetchOverride.mode();
if ( fetchType == FetchType.LAZY && fetchMode == FetchMode.JOIN ) {
if ( fetchOverride.fetch() == FetchType.LAZY
&& fetchOverride.mode() == FetchMode.JOIN ) {
throw new AnnotationException(
"Fetch profile '" + name
+ "' has a '@FetchOverride' with 'fetch=LAZY' and 'mode=JOIN'"
Expand Down Expand Up @@ -484,28 +478,29 @@ public static Map<ClassDetails, InheritanceState> buildInheritanceStates(
collector.registerEmbeddableSubclass( superEntityState.getClassDetails(), classDetails );
}
}
logMixedInheritance( classDetails, superclassState, state );
if ( superclassState.getType() != null ) {
state.setType( superclassState.getType() );
checkMixedInheritance( classDetails, superclassState, state );
final var inheritanceType = superclassState.getType();
if ( inheritanceType != null ) {
state.setType( inheritanceType );
}
}
switch ( classType ) {
case ENTITY:
case MAPPED_SUPERCLASS:
case EMBEDDABLE:
case ENTITY, MAPPED_SUPERCLASS, EMBEDDABLE:
inheritanceStatePerClass.put( classDetails, state );
}
}
return inheritanceStatePerClass;
}

private static void logMixedInheritance(ClassDetails classDetails, InheritanceState superclassState, InheritanceState state) {
if ( state.getType() != null && superclassState.getType() != null ) {
final boolean nonDefault = InheritanceType.SINGLE_TABLE != state.getType();
final boolean mixingStrategy = state.getType() != superclassState.getType();
private static void checkMixedInheritance(ClassDetails classDetails, InheritanceState superclassState, InheritanceState state) {
final var inheritanceType = state.getType();
final var superclassInheritanceType = superclassState.getType();
if ( inheritanceType != null && superclassInheritanceType != null ) {
final boolean nonDefault = InheritanceType.SINGLE_TABLE != inheritanceType;
final boolean mixingStrategy = inheritanceType != superclassInheritanceType;
if ( nonDefault && mixingStrategy ) {
throw new AnnotationException( "Entity '" + classDetails.getName()
+ "' may not override the inheritance mapping strategy '" + superclassState.getType()
+ "' may not override the inheritance mapping strategy '" + superclassInheritanceType
+ "' of its hierarchy"
+ "' (each entity hierarchy has a single inheritance mapping strategy)" );
}
Expand Down
Loading