Skip to content

Commit be91244

Browse files
committed
HHH-19542: Use the property.value table instead of the columns table, which in case of a nested component, was null.
1 parent 6b1aed9 commit be91244

File tree

9 files changed

+20
-160
lines changed

9 files changed

+20
-160
lines changed

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -457,15 +457,6 @@ public Table getTable() {
457457
return persistentClass.getTable();
458458
}
459459

460-
@Override
461-
public Table getSecondaryTable(String tableName) {
462-
final Join join = persistentClass.getSecondaryTable( tableName );
463-
if ( join != null) {
464-
return join.getTable();
465-
}
466-
return null;
467-
}
468-
469460
@Override
470461
public boolean isComponent() {
471462
return false;

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,6 @@ public Table getTable() {
260260
return collection.getCollectionTable();
261261
}
262262

263-
@Override
264-
public Table getSecondaryTable(String tableName) {
265-
throw new AssertionFailure( "Cannot get secondary table for collection" );
266-
}
267-
268263
@Override
269264
public void addProperty(Property prop, MemberDetails memberDetails, ClassDetails declaringClass) {
270265
throw new AssertionFailure( "Cannot add property to a collection" );

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

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -221,23 +221,21 @@ public String getEntityName() {
221221

222222
@Override
223223
public void addProperty(Property property, MemberDetails attributeMemberDetails, AnnotatedColumns columns, ClassDetails declaringClass) {
224-
//Ejb3Column.checkPropertyConsistency( ); //already called earlier
224+
//AnnotatedColumn.checkPropertyConsistency( ); //already called earlier
225225
// Check table matches between the component and the columns
226226
// if not, change the component table if no properties are set
227227
// if a property is set already the core cannot support that
228-
if ( columns != null ) {
229-
final Table table = columns.getTable();
230-
if ( !table.equals( getTable() ) ) {
231-
if ( component.getPropertySpan() == 0 ) {
232-
component.setTable( table );
233-
}
234-
else {
235-
throw new AnnotationException(
236-
"Embeddable class '" + component.getComponentClassName()
237-
+ "' has properties mapped to two different tables"
238-
+ " (all properties of the embeddable class must map to the same table)"
239-
);
240-
}
228+
final Table table = property.getValue().getTable();
229+
if ( !table.equals( getTable() ) ) {
230+
if ( component.getPropertySpan() == 0 ) {
231+
component.setTable( table );
232+
}
233+
else {
234+
throw new AnnotationException(
235+
"Embeddable class '" + component.getComponentClassName()
236+
+ "' has properties mapped to two different tables"
237+
+ " (all properties of the embeddable class must map to the same table)"
238+
);
241239
}
242240
}
243241
addProperty( property, attributeMemberDetails, declaringClass );
@@ -273,11 +271,6 @@ public Table getTable() {
273271
return component.getTable();
274272
}
275273

276-
@Override
277-
public Table getSecondaryTable(String tableName) {
278-
return parent.getSecondaryTable(tableName);
279-
}
280-
281274
@Override
282275
public void addProperty(Property prop, MemberDetails attributeMemberDetails, ClassDetails declaringClass) {
283276
handleGenericComponentProperty( prop, attributeMemberDetails, getContext() );

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

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.hibernate.mapping.Selectable;
4242
import org.hibernate.mapping.SimpleValue;
4343
import org.hibernate.mapping.SingleTableSubclass;
44-
import org.hibernate.mapping.Table;
4544
import org.hibernate.mapping.Value;
4645
import org.hibernate.metamodel.mapping.EntityDiscriminatorMapping;
4746
import org.hibernate.metamodel.spi.EmbeddableInstantiator;
@@ -982,7 +981,8 @@ static Component createEmbeddable(
982981
MetadataBuildingContext context) {
983982
final Component component = new Component( context, propertyHolder.getPersistentClass() );
984983
component.setEmbedded( isComponentEmbedded );
985-
component.setTable( resolveTable( propertyHolder, inferredData.getClassOrElementType() ) );
984+
// yuk
985+
component.setTable( propertyHolder.getTable() );
986986
if ( isIdentifierMapper
987987
|| isComponentEmbedded && inferredData.getPropertyName() == null ) {
988988
component.setComponentClassName( component.getOwner().getClassName() );
@@ -1003,27 +1003,6 @@ static Component createEmbeddable(
10031003
return component;
10041004
}
10051005

1006-
private static Table resolveTable(PropertyHolder propertyHolder, TypeDetails embeddableClass) {
1007-
return embeddableClass == null ? propertyHolder.getTable() : resolveTable( propertyHolder, embeddableClass.determineRawClass() );
1008-
}
1009-
1010-
private static Table resolveTable(PropertyHolder propertyHolder, ClassDetails embeddableClass) {
1011-
if ( embeddableClass != null ) {
1012-
for ( FieldDetails fieldDetails : embeddableClass.getFields() ) {
1013-
if ( fieldDetails.hasDirectAnnotationUsage( Column.class ) ) {
1014-
final String tableName = fieldDetails.getDirectAnnotationUsage( Column.class ).table();
1015-
if ( !tableName.isBlank() ) {
1016-
final Table secondaryTable = propertyHolder.getSecondaryTable( tableName );
1017-
if ( secondaryTable != null ) {
1018-
return secondaryTable;
1019-
}
1020-
}
1021-
}
1022-
}
1023-
}
1024-
return propertyHolder.getTable();
1025-
}
1026-
10271006
private static void applyColumnNamingPattern(Component component, PropertyData inferredData) {
10281007
final Class<?> componentClass = component.getComponentClass();
10291008
if ( componentClass == null || Map.class.equals( componentClass ) ) {

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ public interface PropertyHolder {
3131

3232
Table getTable();
3333

34-
Table getSecondaryTable(String tableName);
35-
3634
void addProperty(Property prop, MemberDetails memberDetails, ClassDetails declaringClass);
3735

3836
void addProperty(Property prop, MemberDetails memberDetails, AnnotatedColumns columns, ClassDetails declaringClass);

hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/embedded/EmbeddableA.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class EmbeddableA {
2020
@AttributeOverrides({@AttributeOverride(name = "embedAttrB" , column = @Column(table = "TableB"))})
2121
private EmbeddableB embedB;
2222

23+
@Column(table = "TableB")
2324
private String embedAttrA;
2425

2526
public EmbeddableB getEmbedB() {

hibernate-core/src/test/java/org/hibernate/orm/test/embeddable/EmbeddableAsSecondaryTableTest.java

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

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/embeddable/NestedEmbeddedObjectWithASecondaryTableTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import jakarta.persistence.Table;
1616
import org.hibernate.boot.MetadataSources;
1717
import org.hibernate.testing.orm.junit.JiraKey;
18-
import org.hibernate.testing.orm.junit.NotImplementedYet;
1918
import org.hibernate.testing.orm.junit.ServiceRegistry;
2019
import org.hibernate.testing.orm.junit.ServiceRegistryScope;
2120
import org.junit.jupiter.api.Test;
@@ -32,7 +31,6 @@
3231
class NestedEmbeddedObjectWithASecondaryTableTest {
3332

3433
@Test
35-
@NotImplementedYet
3634
void testNestedEmbeddedAndSecondaryTables(ServiceRegistryScope registryScope) {
3735
final MetadataSources metadataSources = new MetadataSources( registryScope.getRegistry() )
3836
.addAnnotatedClasses( Book.class, Author.class, House.class );
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
package org.hibernate.orm.test.records;
66

7+
import jakarta.persistence.AttributeOverride;
78
import jakarta.persistence.Column;
89
import jakarta.persistence.Embeddable;
910
import jakarta.persistence.Entity;
@@ -21,10 +22,10 @@
2122

2223
@JiraKey("HHH-19542")
2324
@DomainModel(annotatedClasses = {
24-
RecordEmbeddedAsSecondaryTableTest.UserEntity.class
25+
RecordNestedEmbeddedWithASecondaryTableTest.UserEntity.class
2526
})
2627
@SessionFactory
27-
public class RecordEmbeddedAsSecondaryTableTest {
28+
public class RecordNestedEmbeddedWithASecondaryTableTest {
2829

2930
private UserEntity user;
3031

@@ -70,6 +71,8 @@ protected UserEntity() {
7071

7172
@Embeddable
7273
public record Person(
74+
@AttributeOverride(name = "firstName", column = @Column(table = "Person"))
75+
@AttributeOverride(name = "lastName", column = @Column(table = "Person"))
7376
FullName fullName,
7477
@Column(table = "Person")
7578
Integer age) {

0 commit comments

Comments
 (0)