openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marc Logemann>
Subject inverse OneToMany relation - getting weird
Date Fri, 13 Nov 2009 13:03:44 GMT

after struggling for several hours, i need to ask for help.

Following scenario.....

DB Table: Father
INT oid

DB Table: Childs
INT oid
INT father_oid

Java Entity: Father
@OneToMany(cascade = CascadeType.PERSIST, mappedBy = "father")
  private List<Child> childList;

Java Entity: Child
@ManyToOne(cascade = CascadeType.PERSIST)
@ElementJoinColumn(name="father_oid", referencedColumnName="oid")
protected Father father;

When i try to persist a Father, i am getting:

<openjpa-1.2.0-r422266:683325 fatal user error>  
org.apache.openjpa.persistence.ArgumentException: Field  
"Father.childList" declares "Child.father" as its mapped-by field, but  
this field is not a direct relation. at......

Ok, then i changed Child to:

Java Entity: Child
@ManyToOne(cascade = CascadeType.PERSIST)
@Column(name = "father_oid")
protected Father father;

When i now do persist a Father object, both DB records (Father and  
Childs) are filled with records but the FK column in Child  
(father_oid) is empty. So the FK relation is broken but it did persist  
childs, which is somehow weird.

So whatever i do, i never get a fully persisted graph with correct FK  

Can anyone give me a hint what i am doing wrong here?

Thanks a lot.

Marc Logemann

View raw message