I want to create and delete one of ProductPrice, update is working properly but others gives exception,
there are two relation for ProductPrice
PRODUCT CLASSCode:
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>();
}
PRODUCTPRICE CLASSCode:
public class ProductPrice extends GenericEntitySimple {
@ManyToOne(targetEntity = Product.class, optional=false)
@JoinColumn(name = "PRODUCT_ID", referencedColumnName = "ID")
private Product product;
}
Code:
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);
}
it throws this error:
Code:
Jun 17, 2013 3:45:29 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet appServlet threw exception
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.netasoft.commerce.framework.catalog.model.ProductAttrValueExt
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:243)
at org.hibernate.collection.AbstractPersistentCollection.getOrphans(AbstractPersistentCollection.java:930)
at org.hibernate.collection.PersistentBag.getOrphans(PersistentBag.java:143)
at org.hibernate.engine.CollectionEntry.getOrphans(CollectionEntry.java:373)
at org.hibernate.engine.Cascade.deleteOrphans(Cascade.java:471)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:455)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:362)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:338)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:204)
at org.hibernate.engine.Cascade.cascade(Cascade.java:161)
at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:154)
at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:145)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:88)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
I cannot find documentation about this situation. I think Map lists cache cause this error. Any well prepared documentation suggestions is approved, also. Thank you...