Note that there are some explanatory texts on larger screens.

plurals
  1. POCascadeType problem in One to Many Relation
    primarykey
    data
    text
    <p>I have two classes which have a Unidirectional One to Many relation with each other.</p> <pre><code>public class Offer{ ... @OneToMany(cascade=CascadeType.ALL) @JoinTable(name = "Offer_Fields", joinColumns = @JoinColumn(name = "OFFER_ID"), inverseJoinColumns = @JoinColumn(name = "FIELDMAPPER_ID")) private Set&lt;FieldMapper&gt; fields = new HashSet&lt;FieldMapper&gt;(); } @Entity @Table(name = "FieldMapper") public class FieldMapper implements Serializable { @Id @Column(name = "FIELDMAPPER_ID") @GeneratedValue private int id; @OneToOne(cascade=CascadeType.ALL) @JoinColumn(name = "multilingual_field_fk") private MultiLingual field; @OneToOne(cascade=CascadeType.ALL) @JoinColumn(name = "multilingual_value_fk") private MultiLingual value; } </code></pre> <p>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:</p> <pre><code>org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions </code></pre> <p>and when I change CascadeType to something else I got this error:</p> <pre><code>org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.RCSTT.library.FieldMapper </code></pre> <p>and here is where I save Offer :</p> <pre><code>public void insert(Offer offer) throws SQLException { Session session = HibernateUtil.getSession(); Transaction tx = session.beginTransaction(); session.save(offer); tx.commit(); session.close(); } </code></pre> <p>and I don't use session in somewhere else.</p> <p>in <code>tx.commit();</code> line throws explained exceptions.</p> <p>Thanks for your help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload