Skip to content

Commit 3411191

Browse files
The-Huginnbeikov
authored andcommitted
[HHH-17288] Reference primary key only if all properties match
1 parent 72842e5 commit 3411191

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ private void bindTargetManyToOne(
210210
final KeyValue targetEntityIdentifier = targetEntity.getIdentifier();
211211
boolean referenceToPrimaryKey = mappedBy == null
212212
|| targetEntityIdentifier instanceof Component
213-
&& ( (Component) targetEntityIdentifier ).hasProperty( mappedBy );
213+
&& ( (Component) targetEntityIdentifier ).matchesAllProperties( mappedBy );
214214
oneToOne.setReferenceToPrimaryKey( referenceToPrimaryKey );
215215

216216
final String propertyRef = oneToOne.getReferencedPropertyName();

hibernate-core/src/main/java/org/hibernate/mapping/Component.java

+7
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,13 @@ public Property getProperty(String propertyName) throws MappingException {
506506
throw new MappingException("component: " + componentClassName + " property not found: " + propertyName);
507507
}
508508

509+
public boolean matchesAllProperties(String... propertyNames) {
510+
return properties.size() == propertyNames.length &&
511+
new HashSet<>(properties.stream().map(Property::getName)
512+
.collect(toList()))
513+
.containsAll(List.of(propertyNames));
514+
}
515+
509516
public boolean hasProperty(String propertyName) {
510517
for ( Property prop : properties ) {
511518
if ( prop.getName().equals(propertyName) ) {

0 commit comments

Comments
 (0)