mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-17 00:24:57 +00:00
HHH-15379 NPE building mapping from HBM for collections targeting a class that does not have an HBM mapping
This commit is contained in:
parent
c553d35a86
commit
321af904df
@ -3178,19 +3178,7 @@ private void bindCollectionTable() {
|
|||||||
final PluralAttributeElementSourceOneToMany elementSource =
|
final PluralAttributeElementSourceOneToMany elementSource =
|
||||||
(PluralAttributeElementSourceOneToMany) pluralAttributeSource.getElementSource();
|
(PluralAttributeElementSourceOneToMany) pluralAttributeSource.getElementSource();
|
||||||
|
|
||||||
final PersistentClass persistentClass = mappingDocument.getMetadataCollector()
|
final PersistentClass persistentClass = getReferencedEntityBinding( elementSource.getReferencedEntityName() );
|
||||||
.getEntityBinding( elementSource.getReferencedEntityName() );
|
|
||||||
if ( persistentClass == null ) {
|
|
||||||
throw new MappingException(
|
|
||||||
String.format(
|
|
||||||
Locale.ENGLISH,
|
|
||||||
"Association [%s] references an unmapped entity [%s]",
|
|
||||||
pluralAttributeSource.getAttributeRole().getFullPath(),
|
|
||||||
pluralAttributeSource.getAttributeRole().getFullPath()
|
|
||||||
),
|
|
||||||
mappingDocument.getOrigin()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// even though <key/> defines a property-ref I do not see where legacy
|
// even though <key/> defines a property-ref I do not see where legacy
|
||||||
// code ever attempts to use that to "adjust" the table in its use to
|
// code ever attempts to use that to "adjust" the table in its use to
|
||||||
@ -3289,7 +3277,7 @@ protected void createBackReferences() {
|
|||||||
&& !collectionBinding.getKey().isNullable() ) {
|
&& !collectionBinding.getKey().isNullable() ) {
|
||||||
// for non-inverse one-to-many, with a not-null fk, add a backref!
|
// for non-inverse one-to-many, with a not-null fk, add a backref!
|
||||||
String entityName = ( (OneToMany) collectionBinding.getElement() ).getReferencedEntityName();
|
String entityName = ( (OneToMany) collectionBinding.getElement() ).getReferencedEntityName();
|
||||||
PersistentClass referenced = mappingDocument.getMetadataCollector().getEntityBinding( entityName );
|
PersistentClass referenced = getReferencedEntityBinding( entityName );
|
||||||
Backref prop = new Backref();
|
Backref prop = new Backref();
|
||||||
prop.setName( '_' + collectionBinding.getOwnerEntityName() + "." + pluralAttributeSource.getName() + "Backref" );
|
prop.setName( '_' + collectionBinding.getOwnerEntityName() + "." + pluralAttributeSource.getName() + "Backref" );
|
||||||
prop.setUpdateable( false );
|
prop.setUpdateable( false );
|
||||||
@ -3460,8 +3448,7 @@ else if ( getPluralAttributeSource().getElementSource() instanceof PluralAttribu
|
|||||||
);
|
);
|
||||||
collectionBinding.setElement( elementBinding );
|
collectionBinding.setElement( elementBinding );
|
||||||
|
|
||||||
final PersistentClass referencedEntityBinding = mappingDocument.getMetadataCollector()
|
final PersistentClass referencedEntityBinding = getReferencedEntityBinding( elementSource.getReferencedEntityName() );
|
||||||
.getEntityBinding( elementSource.getReferencedEntityName() );
|
|
||||||
|
|
||||||
if ( useEntityWhereClauseForCollections() ) {
|
if ( useEntityWhereClauseForCollections() ) {
|
||||||
// For a one-to-many association, there are 2 possible sources of "where" clauses that apply
|
// For a one-to-many association, there are 2 possible sources of "where" clauses that apply
|
||||||
@ -3526,9 +3513,7 @@ else if ( getPluralAttributeSource().getElementSource() instanceof PluralAttribu
|
|||||||
|
|
||||||
getCollectionBinding().setElement( elementBinding );
|
getCollectionBinding().setElement( elementBinding );
|
||||||
|
|
||||||
final PersistentClass referencedEntityBinding = mappingDocument.getMetadataCollector().getEntityBinding(
|
final PersistentClass referencedEntityBinding = getReferencedEntityBinding( elementSource.getReferencedEntityName() );
|
||||||
elementSource.getReferencedEntityName()
|
|
||||||
);
|
|
||||||
|
|
||||||
// Collection#setWhere is used to set the "where" clause that applies to the collection table
|
// Collection#setWhere is used to set the "where" clause that applies to the collection table
|
||||||
// (which is the join table for a many-to-many association).
|
// (which is the join table for a many-to-many association).
|
||||||
@ -3633,6 +3618,24 @@ else if ( getPluralAttributeSource().getElementSource() instanceof PluralAttribu
|
|||||||
getCollectionBinding().setWhere( getPluralAttributeSource().getWhere() );
|
getCollectionBinding().setWhere( getPluralAttributeSource().getWhere() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PersistentClass getReferencedEntityBinding(String referencedEntityName) {
|
||||||
|
PersistentClass entityBinding = mappingDocument.getMetadataCollector().getEntityBinding(
|
||||||
|
referencedEntityName
|
||||||
|
);
|
||||||
|
if ( entityBinding == null ) {
|
||||||
|
throw new MappingException(
|
||||||
|
String.format(
|
||||||
|
Locale.ENGLISH,
|
||||||
|
"Collection [%s] references an unmapped entity [%s]",
|
||||||
|
getPluralAttributeSource().getAttributeRole().getFullPath(),
|
||||||
|
referencedEntityName
|
||||||
|
),
|
||||||
|
getMappingDocument().getOrigin()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return entityBinding;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean useEntityWhereClauseForCollections() {
|
private boolean useEntityWhereClauseForCollections() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user