|
6 | 6 |
|
7 | 7 | import jakarta.persistence.CacheRetrieveMode; |
8 | 8 | import jakarta.persistence.CacheStoreMode; |
| 9 | +import jakarta.persistence.Entity; |
9 | 10 | import jakarta.persistence.EntityGraph; |
10 | 11 | import jakarta.persistence.EntityNotFoundException; |
11 | 12 | import jakarta.persistence.FindOption; |
@@ -1526,21 +1527,30 @@ public EntityPersister getEntityPersister(final String entityName, final Object |
1526 | 1527 | return requireEntityPersister( guessEntityName( object ) ); |
1527 | 1528 | } |
1528 | 1529 | else { |
1529 | | - // try block is a hack around fact that currently tuplizers are not |
1530 | | - // given the opportunity to resolve a subclass entity name. this |
1531 | | - // allows the (we assume custom) interceptor the ability to |
| 1530 | + // try block is a hack around fact that currently tuplizers are |
| 1531 | + // not given the opportunity to resolve a subclass entity name. |
| 1532 | + // This allows the (we assume custom) interceptor the ability to |
1532 | 1533 | // influence this decision if we were not able to based on the |
1533 | 1534 | // given entityName |
1534 | 1535 | try { |
1535 | 1536 | return requireEntityPersister( entityName ) |
1536 | 1537 | .getSubclassEntityPersister( object, getFactory() ); |
1537 | 1538 | } |
1538 | | - catch ( HibernateException e ) { |
| 1539 | + catch ( UnknownEntityTypeException uee ) { |
1539 | 1540 | try { |
1540 | 1541 | return getEntityPersister( null, object ); |
1541 | 1542 | } |
1542 | | - catch ( HibernateException e2 ) { |
1543 | | - throw e; |
| 1543 | + catch ( HibernateException e ) { |
| 1544 | + final Class<?> objectClass = object.getClass(); |
| 1545 | + final String problem = |
| 1546 | + objectClass.isAnnotationPresent( Entity.class ) |
| 1547 | + ? "does not belong to this persistence unit" |
| 1548 | + : "is not annotated '@Entity'"; |
| 1549 | + throw new UnknownEntityTypeException( |
| 1550 | + uee.getMessage() |
| 1551 | + + " ('" + objectClass.getSimpleName() + "' " + problem + ")", |
| 1552 | + e |
| 1553 | + ); |
1544 | 1554 | } |
1545 | 1555 | } |
1546 | 1556 | } |
|
0 commit comments