File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Binding tow tables - TopLink Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Binding tow tables - TopLink" Watch "Binding tow tables - TopLink" New topic
Author

Binding tow tables - TopLink

abu alfouz
Ranch Hand

Joined: Nov 20, 2006
Posts: 44
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?


SCJP 1.5
SCWCD 1.4
Shailesh Kini
Ranch Hand

Joined: Oct 17, 2001
Posts: 153
Abu,

Did you try to using @OneToOne(cascade=CascadeType.ALL) mapping to Address from your Person Object?


Shailesh Kini.
Mike Keith
author
Ranch Hand

Joined: Jul 14, 2005
Posts: 304
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).


-Mike
Pro JPA 2: Mastering the Java Persistence API
abu alfouz
Ranch Hand

Joined: Nov 20, 2006
Posts: 44
How can I do that from JDeveloper?
 
 
subject: Binding tow tables - TopLink
 
Threads others viewed
CMR Relations one-to-many
Delete Query problem: Failure to Commit HQL Delete Transaction
[Hibernate] How to handle DB history - i.e., insert only, no updates
Merge operation does not remove from db dependent objects?
(Hibernate) lazy loading even when no association between classes ?
IntelliJ Java IDE