mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-15 15:44:55 +00:00
[HHH-17288] Reference primary key only if all properties match
This commit is contained in:
parent
72842e5d54
commit
34111914b3
@ -210,7 +210,7 @@ private void bindTargetManyToOne(
|
||||
final KeyValue targetEntityIdentifier = targetEntity.getIdentifier();
|
||||
boolean referenceToPrimaryKey = mappedBy == null
|
||||
|| targetEntityIdentifier instanceof Component
|
||||
&& ( (Component) targetEntityIdentifier ).hasProperty( mappedBy );
|
||||
&& ( (Component) targetEntityIdentifier ).matchesAllProperties( mappedBy );
|
||||
oneToOne.setReferenceToPrimaryKey( referenceToPrimaryKey );
|
||||
|
||||
final String propertyRef = oneToOne.getReferencedPropertyName();
|
||||
|
@ -506,6 +506,13 @@ public Property getProperty(String propertyName) throws MappingException {
|
||||
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) {
|
||||
for ( Property prop : properties ) {
|
||||
if ( prop.getName().equals(propertyName) ) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user