HHH-12440 - Fix audited associations that use mapped-by references to embeddable attributes.
This commit is contained in:
parent
8f6800e97f
commit
09cd41e382
|
@ -76,7 +76,6 @@ import org.hibernate.mapping.Table;
|
||||||
import org.hibernate.mapping.Value;
|
import org.hibernate.mapping.Value;
|
||||||
import org.hibernate.type.BagType;
|
import org.hibernate.type.BagType;
|
||||||
import org.hibernate.type.ComponentType;
|
import org.hibernate.type.ComponentType;
|
||||||
import org.hibernate.type.CustomType;
|
|
||||||
import org.hibernate.type.ListType;
|
import org.hibernate.type.ListType;
|
||||||
import org.hibernate.type.ManyToOneType;
|
import org.hibernate.type.ManyToOneType;
|
||||||
import org.hibernate.type.MapType;
|
import org.hibernate.type.MapType;
|
||||||
|
@ -878,7 +877,7 @@ public final class CollectionMetadataGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getMappedBy(Table collectionTable, PersistentClass referencedClass) {
|
private String getMappedBy(Table collectionTable, PersistentClass referencedClass) {
|
||||||
return getMappedBy( referencedClass, new ValueHolder( collectionTable ) );
|
return getMappedBy( referencedClass, new ValueHolder( collectionTable, propertyValue.getMappedByProperty() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getMappedBy(PersistentClass referencedClass, ValueHolder valueHolder) {
|
private String getMappedBy(PersistentClass referencedClass, ValueHolder valueHolder) {
|
||||||
|
@ -943,7 +942,11 @@ public final class CollectionMetadataGenerator {
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked"})
|
@SuppressWarnings({"unchecked"})
|
||||||
private String searchMappedBy(PersistentClass referencedClass, Table collectionTable) {
|
private String searchMappedBy(PersistentClass referencedClass, Table collectionTable) {
|
||||||
final Iterator<Property> properties = referencedClass.getPropertyIterator();
|
return searchMappedBy( referencedClass.getPropertyIterator(), collectionTable );
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private String searchMappedBy(Iterator<Property> properties, Table collectionTable) {
|
||||||
while ( properties.hasNext() ) {
|
while ( properties.hasNext() ) {
|
||||||
final Property property = properties.next();
|
final Property property = properties.next();
|
||||||
if ( property.getValue() instanceof Collection ) {
|
if ( property.getValue() instanceof Collection ) {
|
||||||
|
@ -953,6 +956,17 @@ public final class CollectionMetadataGenerator {
|
||||||
return property.getName();
|
return property.getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if ( property.getValue() instanceof Component ) {
|
||||||
|
// HHH-12240
|
||||||
|
// Should we find an embeddable, we should traverse it as well to see if the collection table
|
||||||
|
// happens to be an attribute inside the embeddable rather than directly on the entity.
|
||||||
|
final Component component = (Component) property.getValue();
|
||||||
|
|
||||||
|
final String mappedBy = searchMappedBy( component.getPropertyIterator(), collectionTable );
|
||||||
|
if ( mappedBy != null ) {
|
||||||
|
return property.getName() + "_" + mappedBy;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -979,6 +993,13 @@ public final class CollectionMetadataGenerator {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getMappedByPropertyValue(ValueHolder valueHolder) {
|
||||||
|
if ( valueHolder.getMappedByProperty() != null ) {
|
||||||
|
return valueHolder.getMappedByProperty();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private PersistentClass getReferenceCollectionClass(Collection collectionValue) {
|
private PersistentClass getReferenceCollectionClass(Collection collectionValue) {
|
||||||
PersistentClass referencedClass = null;
|
PersistentClass referencedClass = null;
|
||||||
if ( collectionValue.getElement() instanceof OneToMany ) {
|
if ( collectionValue.getElement() instanceof OneToMany ) {
|
||||||
|
@ -1003,6 +1024,7 @@ public final class CollectionMetadataGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ValueHolder {
|
private class ValueHolder {
|
||||||
|
private String mappedByProperty;
|
||||||
private Collection collection;
|
private Collection collection;
|
||||||
private Table table;
|
private Table table;
|
||||||
|
|
||||||
|
@ -1010,8 +1032,9 @@ public final class CollectionMetadataGenerator {
|
||||||
this.collection = collection;
|
this.collection = collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueHolder(Table table) {
|
public ValueHolder(Table table, String mappedByProperty) {
|
||||||
this.table = table;
|
this.table = table;
|
||||||
|
this.mappedByProperty = mappedByProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection getCollection() {
|
public Collection getCollection() {
|
||||||
|
@ -1021,6 +1044,10 @@ public final class CollectionMetadataGenerator {
|
||||||
public Table getTable() {
|
public Table getTable() {
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getMappedByProperty() {
|
||||||
|
return mappedByProperty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue