[HHH-17288] Reference primary key only if all properties match
This commit is contained in:
parent
72842e5d54
commit
34111914b3
|
@ -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();
|
||||||
|
|
|
@ -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) ) {
|
||||||
|
|
Loading…
Reference in New Issue