Include source entity name and table name (attribute name too ideally) for associations referencing unmapped classes

Description

During mapping initialization, if some class references an unmapped class (e.g. in a <set> or @OneToMany declaration where the targetEntity is not known to Hibernate), an exception is thrown:
org.hibernate.MappingException: Association references unmapped class: com.bar.Foo

Probably in most cases, a mapping is actually missing and adding it solves the issue.
However, there may be the case in which you want to remove or modify the mapping containing the association to the unmapped class. Unfortunately there is no information in the stack trace leading to this mapping.
It would be helpful, if the name of the referencing entity and table were part of the message.

These informations are present at the time the exception is thrown which happens in org.hibernate.cfg.HbmBinder.bindCollectionSecondPass (line 2577 in version 4.3.8).
The line
throw new MappingException( "Association references unmapped class: " + assocClass );
could be refactored to something like
throw new MappingException(String.format("Association %s for table %s references unmapped class: %s", oneToMany.getReferencedEntityName(), oneToMany.getTable().getName(), assocClass));

Environment

4.3.8 and earlier (newer versions unknown); database independent

Assignee

Vlad Mihalcea

Reporter

Günter Graf

Fix versions

Labels

backPortable

None

Suitable for new contributors

Yes, likely

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Minor
Configure