@@ -1634,6 +1634,7 @@ public boolean contains(Object object) {
16341634 pulseTransactionCoordinator ();
16351635
16361636 if ( object == null ) {
1637+ //TODO: this should throw IllegalArgumentException
16371638 return false ;
16381639 }
16391640
@@ -1662,25 +1663,10 @@ public boolean contains(Object object) {
16621663 // an entry in the session's persistence context and the entry reports
16631664 // that the entity has not been removed
16641665 final var entry = persistenceContext .getEntry ( object );
1665- delayedAfterCompletion ();
1666-
16671666 if ( entry == null ) {
1668- if ( lazyInitializer == null && persistenceContext .getEntry ( object ) == null ) {
1669- // check if it is even an entity -> if not throw an exception (per JPA)
1670- try {
1671- final String entityName = getEntityNameResolver ().resolveEntityName ( object );
1672- if ( entityName == null ) {
1673- throw new IllegalArgumentException ( "Could not resolve entity name for class '"
1674- + object .getClass () + "'" );
1675- }
1676- else {
1677- requireEntityPersister ( entityName );
1678- }
1679- }
1680- catch ( HibernateException e ) {
1681- throw new IllegalArgumentException ( "Class '" + object .getClass ()
1682- + "' is not an entity class" , e );
1683- }
1667+ if ( lazyInitializer == null ) {
1668+ // if not an entity, throw an exception, as required by spec
1669+ assertInstanceOfEntityType ( object );
16841670 }
16851671 return false ;
16861672 }
@@ -1696,6 +1682,23 @@ public boolean contains(Object object) {
16961682 }
16971683 }
16981684
1685+ private void assertInstanceOfEntityType (Object object ) {
1686+ try {
1687+ final String entityName = getEntityNameResolver ().resolveEntityName ( object );
1688+ if ( entityName == null ) {
1689+ throw new IllegalArgumentException ( "Could not resolve entity name for class '"
1690+ + object .getClass () + "'" );
1691+ }
1692+ else {
1693+ requireEntityPersister ( entityName );
1694+ }
1695+ }
1696+ catch ( HibernateException e ) {
1697+ throw new IllegalArgumentException ( "Class '" + object .getClass ()
1698+ + "' is not an entity class" , e );
1699+ }
1700+ }
1701+
16991702 @ Override
17001703 public boolean contains (String entityName , Object object ) {
17011704 checkOpenOrWaitingForAutoClose ();
@@ -1739,7 +1742,6 @@ public boolean contains(String entityName, Object object) {
17391742 // an entry in the session's persistence context and the entry reports
17401743 // that the entity has not been removed
17411744 final var entry = persistenceContext .getEntry ( object );
1742- delayedAfterCompletion ();
17431745 return entry != null && !entry .getStatus ().isDeletedOrGone ();
17441746 }
17451747 catch ( MappingException e ) {
0 commit comments