mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
ADD: testcase for wrong lazyload with cache
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package org.tests.model.lazywithcache;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import io.ebean.annotation.Cache;
|
||||
|
||||
/**
|
||||
* Class with @Cache and lazy load property.
|
||||
*
|
||||
* @author Noemi Szemenyei, FOCONIS AG
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
@Cache(enableQueryCache = true)
|
||||
public class ChildWithCache {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
|
||||
String name;
|
||||
|
||||
@Basic(fetch = FetchType.LAZY)
|
||||
String address;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.tests.model.lazywithcache;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
/**
|
||||
* Parent class with ChildWithCache.
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
public class ParentA {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
|
||||
@ManyToOne(optional = true)
|
||||
ChildWithCache child;
|
||||
|
||||
String name;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public ChildWithCache getChild() {
|
||||
return child;
|
||||
}
|
||||
|
||||
public void setChild(ChildWithCache child) {
|
||||
this.child = child;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.tests.model.lazywithcache;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
/**
|
||||
* Parent class with ChildWithCache.
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
public class ParentB {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
|
||||
@ManyToOne(optional = true)
|
||||
ChildWithCache child;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public ChildWithCache getChild() {
|
||||
return child;
|
||||
}
|
||||
|
||||
public void setChild(ChildWithCache child) {
|
||||
this.child = child;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package org.tests.model.lazywithcache;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test with bean cache and lazy loaded property.
|
||||
*
|
||||
* @author Noemi Szemenyei, FOCONIS AG
|
||||
*
|
||||
*/
|
||||
|
||||
public class TestWithCacheAndLazyLoad extends BaseTestCase{
|
||||
|
||||
@Test
|
||||
public void testGetters() {
|
||||
|
||||
ChildWithCache child = new ChildWithCache();
|
||||
child.setId(1L);
|
||||
child.setName("Child With Cache");
|
||||
child.setAddress("Address");
|
||||
DB.save(child);
|
||||
|
||||
ParentA parentA = new ParentA();
|
||||
parentA.setId(1L);
|
||||
parentA.setName("Parent A");
|
||||
parentA.setChild(child);
|
||||
DB.save(parentA);
|
||||
|
||||
ParentB parentB = new ParentB();
|
||||
parentB.setId(1L);
|
||||
parentB.setChild(child);
|
||||
DB.save(parentB);
|
||||
|
||||
|
||||
ParentA tempA = DB.find(ParentA.class, 1L);
|
||||
tempA.getChild().getName(); //load name
|
||||
|
||||
ParentB tempB = DB.find(ParentB.class, 1L);
|
||||
|
||||
ChildWithCache temp = tempB.getChild();
|
||||
//if the next line is commented out, the test passes
|
||||
temp.getName(); //load name from cache --> ebean_intercept.loadedFromCache = true
|
||||
|
||||
String tempLazyProp = temp.getAddress();
|
||||
assertThat(tempLazyProp).isEqualTo("Address");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user