CascadeType problem in One to Many Relation

Posted by Milad.KH on Stack Overflow See other posts from Stack Overflow or by Milad.KH
Published on 2010-05-24T19:57:55Z Indexed on 2010/05/24 20:01 UTC
Read the original article Hit count: 290

Hi

I have two classes which have a Unidirectional One to Many relation with each other.

public class Offer{
    ...
    @OneToMany(cascade=CascadeType.ALL)
    @JoinTable(name = "Offer_Fields",
    joinColumns =
    @JoinColumn(name = "OFFER_ID"),
    inverseJoinColumns =
    @JoinColumn(name = "FIELDMAPPER_ID"))
    private Set<FieldMapper> fields = new HashSet<FieldMapper>();
}

public class FieldMapper{
    ...
}

I want to store an Offer with a set of FieldMapper to database. When I Use CascadeType.ALL in my OneToMany, I got this error:

org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions

and when I change CascadeType to something else I got this error:

org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.RCSTT.library.FieldMapper

Thanks for your help.

© Stack Overflow or respective owner

Related posts about java

Related posts about hibernate