Hi,
1. The mapping can be simplified as follows:
Address.java:
@OneToMany(mappedBy="address", cascade={CascadeType.ALL},
fetch=FetchType.LAZY)
private java.util.Set<Phone> phones;

Phone.java
@ManyToOne
@ Column(name=" ADDR_FK_ID",nullable=true)
private Address address;

2. It will get rid of the two independent mappings trying to update the same
ADDR_FK_ID column.

3. Domain model should ensure referential consistency at object level. For
example,
Address.java:
   public void addPhone(Phone phone) {
        phones.add(phone);
        phone.setAddresss(this);
    }

Phone.java:
  // notice package level accss 
  void setAddress(Address addr) {
       this.address = addr;
  }

  You can ask OpenJPA to manage consistency of inverse relations but at the
cost of slight performance penalty.

4. In O-R mapping, it makes more sense to work with object references than
with identifiers -- that is why Phone should declare a field of Address type
rather than a Long which is primary identifier of Address.

-- 
View this message in context: 
http://n2.nabble.com/OpenJPA---two-sided-relation-between-objects-Issue-tp687050p687104.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to