ProductPriceの 1 つを作成して削除したいのですが、更新は正常に機能していますが、他では例外が発生します
製品クラス
public class Product extends GenericEntity {
@OneToMany(fetch=FetchType.EAGER, mappedBy = "product", targetEntity = ProductPrice.class, cascade = {CascadeType.ALL}, orphanRemoval=true)
@Fetch(FetchMode.SUBSELECT)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region="ncStandardElements")
private List<ProductPrice> productPrices = new ArrayList<ProductPrice>();
@OneToMany(fetch=FetchType.EAGER, mappedBy = "product", targetEntity = ProductPrice.class)
@Fetch(FetchMode.SUBSELECT)
@MapKeyJoinColumn(name="CURRENCY_ID")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region="ncStandardElements")
private Map<Currency, ProductPrice> productPriceMap = new HashMap<Currency, ProductPrice>();
}
製品価格クラス
public class ProductPrice extends GenericEntitySimple {
@ManyToOne(targetEntity = Product.class, optional=false)
@JoinColumn(name = "PRODUCT_ID", referencedColumnName = "ID")
private Product product;
}
public void removeProductPrice(ProductPrice price){
Product p = price.getProduct();
//Map<Currency, ProductPrice> productPriceMap = p.getProductPriceMap();
//productPriceMap.remove(price);
List<ProductPrice> prices = p.getProductPrices();
prices.remove(price);
p.setProductPrices(prices);
productDao.merge(p);
}
価格が同じセッションで作成された場合、削除操作は成功しますが、現在のセッションの前に価格が作成された場合、次のエラーがスローされます。
Jun 13, 2013 3:26:29 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet appServlet threw exception
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.netasoft.commerce.framework.catalog.model.ProductPrice#220]
at org.hibernate.impl.SessionFactoryImpl$2.handleEntityNotFound(SessionFactoryImpl.java:435)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:233)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
MapKeyJoinColumn を完全に取得できず、この状況に関するドキュメントが見つかりません。マップ リストのキャッシュがこのエラーの原因だと思います。十分に準備されたドキュメントの提案も承認されます。