We have an existing application developed using the EJB 2.0 and we migrated to 
EJB 3.0 to openJPA. 
 
The current implementation we only support one class to mapped to one table and 
we don’t support relation built between the managed objects. We wanted to 
enhance to build the relations among the managed objects and at the same time 
support existing code to work after the relations are built between the 
objects. 
 
Lets take an example , I have an Address class and it contains a collections of 
phones ie there is one to many relation b/w the Address and Phone.
 
Now the addressId in the Phone class is mapped as the Column as part of the 
existing code and the new phones collection is added to the Address as part of 
the enhancement which maps.
 
When we persist the Object Address, we get the following exception as the 
column is mapped from two sides on the object graph. 
 
Is there a way in OpenJPA to say the persistence fwk to ignore the column 
mapping when using the relation in an object graph ?
 
I assume, I am able to explain the problem.
 
Error :
 
Caused by: <4|true|0.9.5-incubating> 
org.apache.openjpa.persistence.InvalidStateException: Attempt to set column 
"PHONE.ADDR_FK_ID" to two different values: (class java.lang.Long)"1,964,347", 
(null)"null" This can occur when you fail to set both sides of a two-sided 
relation between objects, or when you map different fields to the same column, 
but you do not keep the values of these fields in synch.
 
 
Code : 
public class Address..
 
private java.util.Set<Phone> phones;
 
@OneToMany( cascade={CascadeType.ALL}, fetch=FetchType.LAZY)
@ElementJoinColumn(name="ADDR_FK_ID", referencedColumnName="ADDR_ID")
public java.util.Set<Phone> getPhones() {
return this.phones;
}
 
public void setPhones(java.util.Set<Phone> phones) {
               this.phones = phones;
}
 
 
public class Phone….
 
private Long addressId
 
@Basic()
@ Column(name=" ADDR_FK_ID",nullable=true)
public Long getAddressId()
{
return this.addressId;
}
 Rgds
Madhu



      

Reply via email to