Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Binding tow tables - TopLink

 
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?
 
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?
 
author
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?
 
Hug your destiny! And hug this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic