"java.lang.IllegalArgumentException: Not an entity" while calling Session.contains() for hbm file based entity

Description

When Metamodel is created based on hbm xml file mapping then wrong entity name is set for MetamodelImpl#entityPersisterMap comparing with annotation based one.

Because of that it is impossible to get entity persister by its class for any entity that has configred entity-name in hbm xml file.

After all this one leads to nasty:

1 2 java.lang.IllegalArgumentException: Not an entity [class ...] at org.hibernate.internal.SessionImpl.contains(SessionImpl.java:2140)

After deep debugging we found that in org.hibernate.boot.model.source.internal.hbm.ModelBinder which is responsible for creation of bindings based on hbm xml files entity-name xml attribute is assigned to PersistenceClass#entityName class mapping:

1 2 3 4 5 6 7 8 private void bindBasicEntityValues( MappingDocument sourceDocument, AbstractEntitySourceImpl entitySource, PersistentClass pc) { pc.setEntityName( entitySource.getEntityNamingSource().getEntityName() ); pc.setJpaEntityName( entitySource.getEntityNamingSource().getJpaEntityName() ); pc.setClassName( entitySource.getEntityNamingSource().getClassName() ); [...]

in opposite to org.hibernate.cfg.annotations.EntityBinder where a class name is assigned to PersistenceClass#entityName

1 2 3 4 public void bindEntity() { pc.setEntityName( annotatedClass.getName() ); pc.setClassName( annotatedClass.getName() ); pc.setJpaEntityName(name);

 

Environment

None

Status

Assignee

Steve Ebersole

Reporter

Łukasz Dęgus

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.4.4

Priority

Major