Fix for #190 - javax.persistence.PersistenceException: Server [null] was not found? at EntityBeanIntercept.loadBean(EntityBeanIntercept.java:693)

This commit is contained in:
Rob Bygrave
2014-09-10 00:00:49 +12:00
parent 2c90b239cd
commit ab9762bbd9
6 changed files with 118 additions and 30 deletions
@@ -0,0 +1,56 @@
package com.avaje.tests.cache;
import org.junit.Assert;
import org.junit.Test;
import com.avaje.ebean.BaseTestCase;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.Query;
import com.avaje.ebean.cache.ServerCache;
import com.avaje.ebeaninternal.api.SpiQuery;
import com.avaje.ebeaninternal.server.autofetch.TunedQueryInfo;
import com.avaje.ebeaninternal.server.querydefn.OrmQueryDetail;
import com.avaje.tests.model.basic.FeatureDescription;
public class TestL2CacheWithSharedBean extends BaseTestCase {
@Test
public void test() {
FeatureDescription f1 = new FeatureDescription();
f1.setName("one");
f1.setDescription(null);
Ebean.save(f1);
ServerCache beanCache = Ebean.getServerCacheManager().getBeanCache(FeatureDescription.class);
beanCache.getStatistics(true);
OrmQueryDetail tunedDetail = new OrmQueryDetail();
tunedDetail.select("name");
TunedQueryInfo tunedInfo = new TunedQueryInfo(null, tunedDetail, 0);
Query<FeatureDescription> query = Ebean.find(FeatureDescription.class).setId(f1.getId());
tunedInfo.autoFetchTune((SpiQuery<?>) query);
query.findUnique(); // PUT into cache
FeatureDescription fd2 = query.findUnique(); // LOAD cache
fd2.getDescription(); // invoke lazy load (this fails)
// load the cache
FeatureDescription fetchOne = Ebean.find(FeatureDescription.class, f1.getId());
Assert.assertNotNull(fetchOne);
Assert.assertEquals(1, beanCache.getStatistics(false).getSize());
FeatureDescription fetchTwo = Ebean.find(FeatureDescription.class, f1.getId());
FeatureDescription fetchThree = Ebean.find(FeatureDescription.class, f1.getId());
Assert.assertSame(fetchTwo, fetchThree);
String description = fetchThree.getDescription();
Assert.assertNull(description);
}
}
@@ -0,0 +1,44 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import com.avaje.ebean.annotation.CacheStrategy;
@CacheStrategy(readOnly = true, useBeanCache = true)
@Entity
@Table(name="feature_desc")
public class FeatureDescription {
@Id
private Integer id;
private String name;
private String description;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}