Skip to content

Commit b253dd2

Browse files
committed
HHH-19542: Testing the idea
1 parent 1c90c93 commit b253dd2

File tree

6 files changed

+21
-16
lines changed

6 files changed

+21
-16
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.util.Collections;
99
import java.util.List;
1010
import java.util.Map;
11-
import java.util.Objects;
1211

1312
import org.hibernate.AnnotationException;
1413
import org.hibernate.boot.spi.MetadataBuildingContext;
@@ -164,7 +163,7 @@ public void checkPropertyConsistency() {
164163
"Column mappings for property '" + propertyName + "' mix updatable with 'updatable=false'"
165164
);
166165
}
167-
if ( !Objects.equals( current.getExplicitTableName(), previous.getExplicitTableName() ) ) {
166+
if ( !current.getExplicitTableName().equals( previous.getExplicitTableName() ) ) {
168167
throw new AnnotationException(
169168
"Column mappings for property '" + propertyName + "' mix distinct secondary tables"
170169
);

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
*/
55
package org.hibernate.boot.model.internal;
66

7+
import java.util.ArrayList;
78
import java.util.HashMap;
9+
import java.util.List;
810
import java.util.Map;
11+
import java.util.Objects;
912

1013
import org.hibernate.AnnotationException;
1114
import org.hibernate.boot.spi.MetadataBuildingContext;
@@ -68,7 +71,7 @@ public class ComponentPropertyHolder extends AbstractPropertyHolder {
6871

6972
private final String embeddedAttributeName;
7073
private final Map<String,AttributeConversionInfo> attributeConversionInfoMap;
71-
private final AnnotatedColumns annotatedColumns;
74+
private final List<AnnotatedColumn> annotatedColumns;
7275

7376
public ComponentPropertyHolder(
7477
Component component,
@@ -99,8 +102,7 @@ public ComponentPropertyHolder(
99102
if ( parent instanceof ComponentPropertyHolder componentHolder ) {
100103
this.annotatedColumns = componentHolder.annotatedColumns;
101104
} else {
102-
this.annotatedColumns = new AnnotatedColumns();
103-
this.annotatedColumns.setPropertyName( inferredData.getPropertyName() );
105+
this.annotatedColumns = new ArrayList<>();
104106
}
105107
}
106108

@@ -228,7 +230,19 @@ public String getEntityName() {
228230
}
229231

230232
public void checkPropertyConsistency() {
231-
this.annotatedColumns.checkPropertyConsistency();
233+
if ( annotatedColumns.size() > 1 ) {
234+
for ( int currentIndex = 1; currentIndex < annotatedColumns.size(); currentIndex++ ) {
235+
final AnnotatedColumn current = annotatedColumns.get( currentIndex );
236+
final AnnotatedColumn previous = annotatedColumns.get( currentIndex - 1 );
237+
if ( !Objects.equals( current.getExplicitTableName(), previous.getExplicitTableName() ) ) {
238+
throw new AnnotationException(
239+
"Embeddable class '" + component.getComponentClassName()
240+
+ "' has properties mapped to two different tables"
241+
+ " (all properties of the embeddable class must map to the same table)"
242+
);
243+
}
244+
}
245+
}
232246
}
233247

234248
@Override
@@ -261,7 +275,7 @@ public void addProperty(Property property, MemberDetails attributeMemberDetails,
261275
if ( column.getExplicitTableName() == null ) {
262276
column.setExplicitTableName( "" );
263277
}
264-
this.annotatedColumns.addColumn( column );
278+
this.annotatedColumns.add( column );
265279
}
266280
}
267281
addProperty( property, attributeMemberDetails, declaringClass );

hibernate-core/src/test/java/org/hibernate/orm/test/records/RecordNestedEmbeddedWithASecondaryTableTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public record Person(
8282
public record FullName(
8383
@Column(table = "Person")
8484
String firstName,
85-
@Column(table = "Person")
85+
// @Column(table = "Person")
8686
String lastName) {
8787

8888
}

hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/components/Component1.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@
44
*/
55
package org.hibernate.orm.test.envers.entities.components;
66

7-
import jakarta.persistence.Column;
87
import jakarta.persistence.Embeddable;
98

109
/**
1110
* @author Adam Warski (adam at warski dot org)
1211
*/
1312
@Embeddable
1413
public class Component1 {
15-
@Column
1614
private String str1;
1715

18-
@Column
1916
private String str2;
2017

2118
public Component1(String str1, String str2) {

hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/components/Component2.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@
44
*/
55
package org.hibernate.orm.test.envers.entities.components;
66

7-
import jakarta.persistence.Column;
87
import jakarta.persistence.Embeddable;
98

109
/**
1110
* @author Adam Warski (adam at warski dot org)
1211
*/
1312
@Embeddable
1413
public class Component2 {
15-
@Column
1614
private String str5;
1715

18-
@Column
1916
private String str6;
2017

2118
public Component2(String str5, String str6) {

hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/components/Component3.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import jakarta.persistence.AttributeOverrides;
99
import jakarta.persistence.Column;
1010
import jakarta.persistence.Embeddable;
11-
1211
import org.hibernate.envers.Audited;
1312
import org.hibernate.envers.NotAudited;
1413

@@ -21,7 +20,6 @@
2120
@Embeddable
2221
@Audited
2322
public class Component3 {
24-
@Column
2523
private String str1;
2624

2725
@AttributeOverrides({

0 commit comments

Comments
 (0)