• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Binding tow tables - TopLink

 
abu alfouz
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ..

I have two tables: PERSON and ADDRESS, the Person object has an Address object inside. The requirements says that when adding a new Person that contains an Address a new Address row must be added (automatically) and when deleting that Person it's Address row must be deleted (automatically). I check the "Private Owned" in the JDeveloper, this make that when adding a new Person it add a new Address but without binding it with that Person (it kept null on ADDRESS_ID on PERSON table).

What should I do?
 
Shailesh Kini
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abu,

Did you try to using @OneToOne(cascade=CascadeType.ALL) mapping to Address from your Person Object?
 
Mike Keith
author
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Abu,

Marking a relationship as private-owned will give you two main features:
a) If the person is deleted then the address will also be deleted
b) If the relationship is broken (the address is removed) then the address will be deleted

If you were using the TopLink API then by registering the Person then the address would have been automatically pesisted, but when using the JPA EntityManager API you need to set the cascade persist option on the relationship. I recommend that you use the CascadeType.ALL option that Shailesh suggested (then you won't need the private-owned option either).
 
abu alfouz
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I do that from JDeveloper?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic