HHH-10614 - Auto evict collection cache throws exception with null values
This commit is contained in:
parent
0ed39c7746
commit
732abea8e5
|
@ -119,17 +119,11 @@ public class CollectionCacheInvalidator
|
|||
if ( oldState != null ) {
|
||||
// in case of updating an entity we perhaps have to decache 2 entity collections, this is the
|
||||
// old one
|
||||
oldId = session.getIdentifier( oldState[i] );
|
||||
oldId = getIdentifier( session, oldState[i] );
|
||||
}
|
||||
Object ref = persister.getPropertyValue( entity, i );
|
||||
Serializable id = null;
|
||||
if ( ref != null ) {
|
||||
id = session.getContextEntityIdentifier( ref );
|
||||
if ( id == null ) {
|
||||
id = session.getSessionFactory().getClassMetadata( ref.getClass() )
|
||||
.getIdentifier( ref, session );
|
||||
}
|
||||
}
|
||||
Serializable id = getIdentifier( session, ref );
|
||||
|
||||
// only evict if the related entity has changed
|
||||
if ( id != null && !id.equals( oldId ) ) {
|
||||
evict( id, collectionPersister, session );
|
||||
|
@ -159,6 +153,18 @@ public class CollectionCacheInvalidator
|
|||
}
|
||||
}
|
||||
|
||||
private Serializable getIdentifier(EventSource session, Object obj) {
|
||||
Serializable id = null;
|
||||
if ( obj != null ) {
|
||||
id = session.getContextEntityIdentifier( obj );
|
||||
if ( id == null ) {
|
||||
id = session.getSessionFactory().getClassMetadata( obj.getClass() )
|
||||
.getIdentifier( obj, session );
|
||||
}
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
private void evict(Serializable id, CollectionPersister collectionPersister, EventSource session) {
|
||||
if ( LOG.isDebugEnabled() ) {
|
||||
LOG.debug( "Evict CollectionRegion " + collectionPersister.getRole() + " for id " + id );
|
||||
|
|
|
@ -283,4 +283,24 @@ public class CollectionCacheEvictionTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateWithNullRelation() {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
User user = new User();
|
||||
user.setName( "User1" );
|
||||
session.persist( user );
|
||||
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
user.setName( "UserUpdate" );
|
||||
session.merge( user );
|
||||
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue