users@glassfish.java.net

Re: entity relation mappings - parent key voilated error

From: <glassfish_at_javadesktop.org>
Date: Wed, 28 Jan 2009 18:23:01 PST

Marina,

This is how I have it...

Table1.java
_____________________
@JoinColumn(name = "R_ID", referencedColumnName = "ID")
    @ManyToOne
    private Table2 table2;


Table2.Java
_______________
   @OneToMany(mappedBy = "table2")
    private Collection<Table1> table1Collection;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "table2Id")
    private Table3 table3;

Table3.java
________________

 @JoinColumn(name = "ID", referencedColumnName = "ID",insertable = false, updatable = false)
    @OneToOne(optional = false)
    private Table2 table2Id;

thats it...

Initially I tried putting two constraints on table 1 itself on R_ID being mapped to ID of table 2 and table 3 but that did not work...it was giving me multiple writable error...
So I put insertable, updatable, nullable all equal to false clause on table3 relationship...but that gave me constraint violation error...

Then I tried putting constraint in table 2 mapping Id in it with the Id in table 3 and now I get parent key not found error...

Let me know if you need more information...thanks for trying to help me...

-Amor
[Message sent by forum member 'amorous' (amorous)]

http://forums.java.net/jive/thread.jspa?messageID=328838