jQuery in Action, 2nd edition*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Possible to find relationship Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Possible to find relationship" Watch "Possible to find relationship" New topic
Author

Possible to find relationship

Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
I have tried @OneToOne, @ManyToOne, @OneToMany and @ManyToMany relaltionships.

And the table's are made successfully. But now my question is, when i look at the table's in database, i can't differntiate whether these table's has which association mean's i can't recognize out of these @OneToOne, @ManyToOne, @OneToMany and @ManyToMany relaltionships, is for which table from database look.


SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
@OneToOne relationship is implemented in different ways
1- sharing the primary key
2- you find, a relation like
table citizen has citizenship column (BLOB) that is a java class for you.

@OneTOMany relationship is implemented with foreign key reference, for
instance. SO you can easily look for foreign key constraint

@ManyToMany relationship is implemented using third intermediary table. You
can find two referencing column (that joins two relations) in this third
intermediary table.


cmbhatt
Chaminda Amarasinghe
Ranch Hand

Joined: May 17, 2006
Posts: 402
I think above explanation is not correct if you generated tables. (Im not 100% sure)

I think in all cases It will create join table if you didnt specify joinColumn

for an example


Owner

@o2o
Child child


Child

@o2o
Owner owner



So for above table structure provider will create Owner, Child tables + ADDITIONAL Owner_Child table having owner_id and child_id columns.
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
So can i conclude that, it's not possible to find out the relationship differnce between @OneToOne uni-directional and @OneToOne bidirectional, when i look in the database.
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Chaminda/ Amandeep

I have this example, does it adhere what I said in my earlier post:






And I got following generated table schema:

[ November 26, 2008: Message edited by: Chandra Bhatt ]
Chaminda Amarasinghe
Ranch Hand

Joined: May 17, 2006
Posts: 402
As i pointed in my last post, here you have used joincolumn so this is a correct implementation and adhere to your earlier post
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Possible to find relationship
 
Similar Threads
annotation for lazy loading
@primarykeyjoincolumn for OnetoMany and ManytoOne?
The "optional" element on @OneToMany and @ManyToMany
Help understanding when to use em.find and query manager and their ability to fetch nested objects
creating an instance variable of a database table type for persistance