[HHH-17288] Reference primary key only if all properties match

This commit is contained in:
The-Huginn 2023-10-11 16:41:02 +02:00 committed by Christian Beikov
parent 72842e5d54
commit 34111914b3
2 changed files with 8 additions and 1 deletions

View File

@ -210,7 +210,7 @@ public class OneToOneSecondPass implements SecondPass {
final KeyValue targetEntityIdentifier = targetEntity.getIdentifier(); final KeyValue targetEntityIdentifier = targetEntity.getIdentifier();
boolean referenceToPrimaryKey = mappedBy == null boolean referenceToPrimaryKey = mappedBy == null
|| targetEntityIdentifier instanceof Component || targetEntityIdentifier instanceof Component
&& ( (Component) targetEntityIdentifier ).hasProperty( mappedBy ); && ( (Component) targetEntityIdentifier ).matchesAllProperties( mappedBy );
oneToOne.setReferenceToPrimaryKey( referenceToPrimaryKey ); oneToOne.setReferenceToPrimaryKey( referenceToPrimaryKey );
final String propertyRef = oneToOne.getReferencedPropertyName(); final String propertyRef = oneToOne.getReferencedPropertyName();

View File

@ -506,6 +506,13 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
throw new MappingException("component: " + componentClassName + " property not found: " + propertyName); throw new MappingException("component: " + componentClassName + " property not found: " + propertyName);
} }
public boolean matchesAllProperties(String... propertyNames) {
return properties.size() == propertyNames.length &&
new HashSet<>(properties.stream().map(Property::getName)
.collect(toList()))
.containsAll(List.of(propertyNames));
}
public boolean hasProperty(String propertyName) { public boolean hasProperty(String propertyName) {
for ( Property prop : properties ) { for ( Property prop : properties ) {
if ( prop.getName().equals(propertyName) ) { if ( prop.getName().equals(propertyName) ) {