1

I am trying to map the classic bi-directional oneToMany using eclipselink. My problem is that when i want to insert a new 'child' i get SQLIntegrityConstraintViolationException.

The database is described like this :

@Entity
@IdClass(KuponPK.class)
@Table(name = "KUPON", schema = "POST", catalog = "")
public class Kupon implements Serializable {

  private Integer id;
  private String spil;
  private Collection<Kombination> kombinationList;

  @OneToMany(mappedBy = "kupon", cascade = CascadeType.PERSIST)
  public Collection<Kombination> getKombinationList() {
    return kombinationList;
  }

public class KuponPK implements Serializable {

  private Integer id;
  private String spil;

  @Id
  @Column(name = "ID", nullable = false, insertable = true, updatable = true, precision = 0)
  public Integer getId() {
    return id;
  }

  @Id
  @Column(name = "SPIL", nullable = false, insertable = true, updatable = true, length = 5)
  public String getSpil() {
    return spil;
  }

@Entity
@Table(name = "KOMBINATION", schema = "POST", catalog = "")
public class Kombination {
  private Integer id;
  private String sorteringOrden;
  private Integer sorteringNr;
  private Integer antalSpillede;
  private BigDecimal odds;
  private Kupon kupon;

  @ManyToOne
  @JoinColumns({@JoinColumn(name = "KUPON_ID", referencedColumnName = "ID", nullable = false, insertable=false, updatable=false),
                @JoinColumn(name = "KUPON_SPIL", referencedColumnName = "SPIL", nullable = false, insertable=false, updatable=false)})
  public Kupon getKupon() {
    return kupon;
  }

In my stateless session i have a Kupon object and i create a new Kombination where i set the Kupon and try to merge, but im getting Internal Exception: java.sql.SQLIntegrityConstraintViolationException: ORA-01400: cannot insert NULL into ("KOMBINATION"."KUPON_ID") which is obvious since its part of primary key

I am setting the Kombination to Kupon and the Kupon to Kombination, but that doesnt make any difference

How can can i tell that the key is inside the Kupon object which im setting in the Kombination object ??

jka_dk
  • 421
  • 1
  • 4
  • 17

0 Answers0