mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1722 - Failing test for - L2 cache throw exception when query with custom ManyToMany relation model
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package org.tests.cache.embeddedid;
|
||||
|
||||
import io.ebean.annotation.Cache;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Cache
|
||||
@Entity
|
||||
public class CEPCategory {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
@Version
|
||||
private Long version;
|
||||
|
||||
public CEPCategory(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
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 Long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package org.tests.cache.embeddedid;
|
||||
|
||||
import io.ebean.annotation.Cache;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OrderColumn;
|
||||
import javax.persistence.Version;
|
||||
import java.util.List;
|
||||
|
||||
@Cache
|
||||
@Entity
|
||||
public class CEPProduct {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
@OrderColumn(name = "priority")
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "product")
|
||||
private List<CEPProductCategory> productCategories;
|
||||
|
||||
@Version
|
||||
private Long version;
|
||||
|
||||
public CEPProduct(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
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 Long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public List<CEPProductCategory> getProductCategories() {
|
||||
return productCategories;
|
||||
}
|
||||
|
||||
public void setProductCategories(List<CEPProductCategory> productCategories) {
|
||||
this.productCategories = productCategories;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.tests.cache.embeddedid;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.IdClass;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
@IdClass(CEPProductCategoryId.class)
|
||||
@Entity
|
||||
public class CEPProductCategory {
|
||||
|
||||
@Id
|
||||
@ManyToOne
|
||||
private CEPCategory category;
|
||||
|
||||
@Id
|
||||
@ManyToOne
|
||||
private CEPProduct product;
|
||||
|
||||
public CEPProductCategory(CEPCategory category, CEPProduct product) {
|
||||
this.category = category;
|
||||
this.product = product;
|
||||
}
|
||||
|
||||
public CEPCategory getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public void setCategory(CEPCategory category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public CEPProduct getProduct() {
|
||||
return product;
|
||||
}
|
||||
|
||||
public void setProduct(CEPProduct product) {
|
||||
this.product = product;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.tests.cache.embeddedid;
|
||||
|
||||
import javax.persistence.Embeddable;
|
||||
import java.util.Objects;
|
||||
|
||||
@Embeddable
|
||||
public class CEPProductCategoryId {
|
||||
|
||||
// primitive id values as part of an EmbeddedId (NPE #1722)
|
||||
private long customerId;
|
||||
private long addressId;
|
||||
|
||||
public long getCustomerId() {
|
||||
return customerId;
|
||||
}
|
||||
|
||||
public void setCustomerId(long customerId) {
|
||||
this.customerId = customerId;
|
||||
}
|
||||
|
||||
public long getAddressId() {
|
||||
return addressId;
|
||||
}
|
||||
|
||||
public void setAddressId(long addressId) {
|
||||
this.addressId = addressId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CEPProductCategoryId that = (CEPProductCategoryId) o;
|
||||
return customerId == that.customerId &&
|
||||
addressId == that.addressId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(customerId, addressId);
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package org.tests.cache.embeddedid;
|
||||
|
||||
import io.ebean.Ebean;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class TestBeanCacheEmbeddedIdPrimitives {
|
||||
|
||||
@Test
|
||||
public void findById() {
|
||||
|
||||
CEPProduct product1a = new CEPProduct("Product 01");
|
||||
Ebean.save(product1a);
|
||||
|
||||
assertNotNull(product1a.getId());
|
||||
|
||||
CEPCategory category1a = new CEPCategory("Category 01");
|
||||
Ebean.save(category1a);
|
||||
|
||||
assertNotNull(category1a.getId());
|
||||
|
||||
CEPProduct product1 = Ebean.find(CEPProduct.class).setUseCache(true).where().eq("id", product1a.getId()).findOne();
|
||||
|
||||
assertNotNull(product1);
|
||||
|
||||
product1.getProductCategories().forEach(customerAddress -> {
|
||||
System.out.println(customerAddress.getCategory());
|
||||
});
|
||||
assertThat(product1.getProductCategories()).isEmpty();
|
||||
|
||||
CEPProduct product2 = Ebean.find(CEPProduct.class).setUseCache(true).where().eq("id", product1a.getId()).findOne();
|
||||
assertNotNull(product2);
|
||||
|
||||
// fail here on null -> long conversion in embedded id
|
||||
product2.getProductCategories().forEach(customerAddress -> {
|
||||
System.out.println(customerAddress.getCategory());
|
||||
});
|
||||
assertThat(product2.getProductCategories()).isEmpty();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user