Skip to content

Commit 282a7b1

Browse files
committed
HHH-10208 - Index and unique-key constraints not properly handled with implicit columns in hbm.xml binding
(cherry picked from commit ec8794b)
1 parent d167599 commit 282a7b1

29 files changed

+177
-832
lines changed

hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import org.hibernate.boot.model.relational.Database;
4646
import org.hibernate.boot.model.relational.ExportableProducer;
4747
import org.hibernate.boot.model.relational.Namespace;
48-
import org.hibernate.boot.model.source.internal.ConstraintSecondPass;
4948
import org.hibernate.boot.model.source.internal.ImplicitColumnNamingSecondPass;
5049
import org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext;
5150
import org.hibernate.boot.spi.InFlightMetadataCollector;
@@ -1484,7 +1483,6 @@ public Join locateJoin(Identifier tableName) {
14841483
private ArrayList<CreateKeySecondPass> createKeySecondPasList;
14851484
private ArrayList<SecondaryTableSecondPass> secondaryTableSecondPassList;
14861485
private ArrayList<QuerySecondPass> querySecondPassList;
1487-
private ArrayList<ConstraintSecondPass> constraintSecondPassList;
14881486
private ArrayList<ImplicitColumnNamingSecondPass> implicitColumnNamingSecondPassList;
14891487

14901488
private ArrayList<SecondPass> generalSecondPassList;
@@ -1517,9 +1515,6 @@ else if ( secondPass instanceof SecondaryTableSecondPass ) {
15171515
else if ( secondPass instanceof QuerySecondPass ) {
15181516
addQuerySecondPass( (QuerySecondPass) secondPass, onTopOfTheQueue );
15191517
}
1520-
else if ( secondPass instanceof ConstraintSecondPass ) {
1521-
addConstraintSecondPass( ( ConstraintSecondPass) secondPass, onTopOfTheQueue );
1522-
}
15231518
else if ( secondPass instanceof ImplicitColumnNamingSecondPass ) {
15241519
addImplicitColumnNamingSecondPass( (ImplicitColumnNamingSecondPass) secondPass );
15251520
}
@@ -1594,13 +1589,6 @@ private void addQuerySecondPass(QuerySecondPass secondPass, boolean onTopOfTheQu
15941589
addSecondPass( secondPass, querySecondPassList, onTopOfTheQueue );
15951590
}
15961591

1597-
private void addConstraintSecondPass(ConstraintSecondPass secondPass, boolean onTopOfTheQueue) {
1598-
if ( constraintSecondPassList == null ) {
1599-
constraintSecondPassList = new ArrayList<ConstraintSecondPass>();
1600-
}
1601-
addSecondPass( secondPass, constraintSecondPassList, onTopOfTheQueue );
1602-
}
1603-
16041592
private void addImplicitColumnNamingSecondPass(ImplicitColumnNamingSecondPass secondPass) {
16051593
if ( implicitColumnNamingSecondPassList == null ) {
16061594
implicitColumnNamingSecondPassList = new ArrayList<ImplicitColumnNamingSecondPass>();
@@ -1637,7 +1625,6 @@ public void processSecondPasses(MetadataBuildingContext buildingContext) {
16371625

16381626
secondPassCompileForeignKeys( buildingContext );
16391627

1640-
processSecondPasses( constraintSecondPassList );
16411628
processUniqueConstraintHolders( buildingContext );
16421629
processJPAIndexHolders( buildingContext );
16431630

hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/ConstraintSecondPass.java

Lines changed: 0 additions & 73 deletions
This file was deleted.

hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/AbstractConstraintSource.java

Lines changed: 0 additions & 74 deletions
This file was deleted.

hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/AbstractEntitySourceImpl.java

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.hibernate.boot.model.source.spi.AttributeRole;
3434
import org.hibernate.boot.model.source.spi.AttributeSource;
3535
import org.hibernate.boot.model.source.spi.AttributeSourceContainer;
36-
import org.hibernate.boot.model.source.spi.ConstraintSource;
3736
import org.hibernate.boot.model.source.spi.EntityHierarchySource;
3837
import org.hibernate.boot.model.source.spi.EntityNamingSource;
3938
import org.hibernate.boot.model.source.spi.EntitySource;
@@ -79,9 +78,6 @@ public abstract class AbstractEntitySourceImpl
7978

8079
private final ToolingHintContext toolingHintContext;
8180

82-
private Map<String, ConstraintSource> constraintMap = new HashMap<String, ConstraintSource>();
83-
84-
8581
protected AbstractEntitySourceImpl(MappingDocument sourceMappingDocument, JaxbHbmEntityBaseDefinition jaxbEntityMapping) {
8682
super( sourceMappingDocument );
8783
this.jaxbEntityMapping = jaxbEntityMapping;
@@ -223,86 +219,12 @@ public AttributeSourceContainer getAttributeSourceContainer() {
223219
public void addAttributeSource(AttributeSource attributeSource) {
224220
attributeSources.add( attributeSource );
225221
}
226-
227-
@Override
228-
public void registerIndexColumn(String constraintName, String logicalTableName, String columnName) {
229-
registerIndexConstraintColumn( constraintName, logicalTableName, columnName );
230-
}
231-
232-
@Override
233-
public void registerUniqueKeyColumn(String constraintName, String logicalTableName, String columnName) {
234-
registerUniqueKeyConstraintColumn( constraintName, logicalTableName, columnName );
235-
}
236222
};
237223
buildAttributeSources( attributeBuildingCallback );
238224

239225
return attributeSources;
240226
}
241227

242-
private void registerIndexConstraintColumn(String constraintName, String logicalTableName, String columnName) {
243-
getOrCreateIndexConstraintSource( constraintName, logicalTableName ).addColumnName( columnName );
244-
}
245-
246-
private IndexConstraintSourceImpl getOrCreateIndexConstraintSource(String constraintName, String logicalTableName) {
247-
IndexConstraintSourceImpl constraintSource = (IndexConstraintSourceImpl) constraintMap.get( constraintName );
248-
if ( constraintSource == null ) {
249-
constraintSource = new IndexConstraintSourceImpl( constraintName, logicalTableName );
250-
constraintMap.put( constraintName, constraintSource );
251-
}
252-
else {
253-
// make sure we have the same table name...
254-
if ( !EqualsHelper.equals( constraintSource.getTableName(), logicalTableName ) ) {
255-
throw new MappingException(
256-
String.format(
257-
Locale.ENGLISH,
258-
"Named relational index [%s] referenced more than one table [%s, %s]",
259-
constraintName,
260-
constraintSource.getTableName() == null
261-
? "null(implicit)"
262-
: constraintSource.getTableName(),
263-
logicalTableName == null
264-
? "null(implicit)"
265-
: logicalTableName
266-
),
267-
origin()
268-
);
269-
}
270-
}
271-
return constraintSource;
272-
}
273-
274-
private void registerUniqueKeyConstraintColumn(String constraintName, String logicalTableName, String columnName) {
275-
getOrCreateUniqueKeyConstraintSource( constraintName, logicalTableName ).addColumnName( columnName );
276-
}
277-
278-
private UniqueKeyConstraintSourceImpl getOrCreateUniqueKeyConstraintSource(String constraintName, String logicalTableName) {
279-
UniqueKeyConstraintSourceImpl constraintSource = (UniqueKeyConstraintSourceImpl) constraintMap.get( constraintName );
280-
if ( constraintSource == null ) {
281-
constraintSource = new UniqueKeyConstraintSourceImpl( constraintName, logicalTableName );
282-
constraintMap.put( constraintName, constraintSource );
283-
}
284-
else {
285-
// make sure we have the same table name...
286-
if ( !EqualsHelper.equals( constraintSource.getTableName(), logicalTableName ) ) {
287-
throw new MappingException(
288-
String.format(
289-
Locale.ENGLISH,
290-
"Named relational unique-key [%s] referenced more than one table [%s, %s]",
291-
constraintName,
292-
constraintSource.getTableName() == null
293-
? "null(implicit)"
294-
: constraintSource.getTableName(),
295-
logicalTableName == null
296-
? "null(implicit)"
297-
: logicalTableName
298-
),
299-
origin()
300-
);
301-
}
302-
}
303-
return constraintSource;
304-
}
305-
306228
protected void buildAttributeSources(AttributesHelper.Callback attributeBuildingCallback) {
307229
AttributesHelper.processAttributes(
308230
sourceMappingDocument(),
@@ -344,22 +266,6 @@ public AttributeSourceContainer getAttributeSourceContainer() {
344266
public void addAttributeSource(AttributeSource attributeSource) {
345267
attributeSources.add( attributeSource );
346268
}
347-
348-
@Override
349-
public void registerIndexColumn(
350-
String constraintName,
351-
String logicalTableName,
352-
String columnName) {
353-
registerIndexConstraintColumn( constraintName, logicalTableName, columnName );
354-
}
355-
356-
@Override
357-
public void registerUniqueKeyColumn(
358-
String constraintName,
359-
String logicalTableName,
360-
String columnName) {
361-
registerUniqueKeyConstraintColumn( constraintName, logicalTableName, columnName );
362-
}
363269
},
364270
joinElement.getAttributes(),
365271
logicalTableName,
@@ -501,11 +407,6 @@ void add(SubclassEntitySourceImpl subclassEntitySource) {
501407
subclassEntitySources.add( subclassEntitySource );
502408
}
503409

504-
@Override
505-
public Collection<ConstraintSource> getConstraints() {
506-
return constraintMap.values();
507-
}
508-
509410
@Override
510411
public Map<String,SecondaryTableSource> getSecondaryTableMap() {
511412
return secondaryTableMap;

hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/AbstractSingularAttributeSourceEmbeddedImpl.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,6 @@ public AttributePath getAttributePathBase() {
7272
public ToolingHintContext getToolingHintContextBaselineForEmbeddable() {
7373
return toolingHintContext;
7474
}
75-
76-
@Override
77-
public void registerIndexConstraintColumn(
78-
String constraintName,
79-
String logicalTableName,
80-
String columnName) {
81-
82-
}
83-
84-
@Override
85-
public void registerUniqueKeyConstraintColumn(
86-
String constraintName, String logicalTableName, String columnName) {
87-
88-
}
8975
},
9076
embeddedAttributeMapping.getEmbeddableMapping(),
9177
nestedAttributeMappings,

0 commit comments

Comments
 (0)