-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: JPA CRUD OneToMany Relation And MapKeyJoinColumn
PostPosted: Mon Jun 17, 2013 8:47 am 
Newbie

Joined: Wed Jan 16, 2013 11:30 am
Posts: 2
I want to create and delete one of ProductPrice, update is working properly but others gives exception,
there are two relation for ProductPrice

PRODUCT CLASS

Code:
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 CLASS

Code:
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...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.