mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-17 16:44:57 +00:00
HHH-12868 Fix NPE when loading entity with CacheConcurrencyStrategy.NONE
This commit is contained in:
parent
9ab285eb58
commit
e43c374f30
@ -535,7 +535,7 @@ public AbstractEntityPersister(
|
||||
|
||||
if ( creationContext.getSessionFactory().getSessionFactoryOptions().isSecondLevelCacheEnabled() ) {
|
||||
this.canWriteToCache = determineCanWriteToCache( persistentClass, cacheAccessStrategy );
|
||||
this.canReadFromCache = determineCanReadFromCache( persistentClass );
|
||||
this.canReadFromCache = determineCanReadFromCache( persistentClass, cacheAccessStrategy );
|
||||
this.cacheAccessStrategy = cacheAccessStrategy;
|
||||
this.isLazyPropertiesCacheable = persistentClass.getRootClass().isLazyPropertiesCacheable();
|
||||
this.naturalIdRegionAccessStrategy = naturalIdRegionAccessStrategy;
|
||||
@ -916,7 +916,11 @@ private boolean determineCanWriteToCache(PersistentClass persistentClass, Entity
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private boolean determineCanReadFromCache(PersistentClass persistentClass) {
|
||||
private boolean determineCanReadFromCache(PersistentClass persistentClass, EntityDataAccess cacheAccessStrategy) {
|
||||
if ( cacheAccessStrategy == null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( persistentClass.isCached() ) {
|
||||
return true;
|
||||
}
|
||||
|
@ -20,13 +20,16 @@
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author Chris Cranford
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-12587")
|
||||
public class CacheAnnotationTests extends BaseCoreFunctionalTestCase {
|
||||
|
||||
private Integer entityId;
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
@ -39,7 +42,8 @@ protected Class<?>[] getAnnotatedClasses() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheConcurrencyStrategyNone() {
|
||||
@TestForIssue(jiraKey = "HHH-12587")
|
||||
public void testCacheWriteConcurrencyStrategyNone() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
NoCacheConcurrencyStrategyEntity entity = new NoCacheConcurrencyStrategyEntity();
|
||||
session.save( entity );
|
||||
@ -48,6 +52,26 @@ public void testCacheConcurrencyStrategyNone() {
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-12868")
|
||||
public void testCacheReadConcurrencyStrategyNone() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
NoCacheConcurrencyStrategyEntity entity = new NoCacheConcurrencyStrategyEntity();
|
||||
entity.setName( "name" );
|
||||
session.save( entity );
|
||||
session.flush();
|
||||
|
||||
this.entityId = entity.getId();
|
||||
|
||||
session.clear();
|
||||
} );
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
NoCacheConcurrencyStrategyEntity entity = session.load( NoCacheConcurrencyStrategyEntity.class, this.entityId );
|
||||
assertEquals( "name", entity.getName() );
|
||||
} );
|
||||
}
|
||||
|
||||
@Entity(name = "NoCacheConcurrencyStrategy")
|
||||
@Cache(usage = CacheConcurrencyStrategy.NONE)
|
||||
public static class NoCacheConcurrencyStrategyEntity {
|
||||
@ -55,6 +79,8 @@ public static class NoCacheConcurrencyStrategyEntity {
|
||||
@GeneratedValue
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
@ -62,5 +88,13 @@ public Integer getId() {
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user