aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate annotations one to many relationship with composite primary key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate annotations one to many relationship with composite primary key" Watch "Hibernate annotations one to many relationship with composite primary key" New topic
Author

Hibernate annotations one to many relationship with composite primary key

Vivek Alampally
Ranch Hand

Joined: Jul 10, 2008
Posts: 67
Hello everybody,

First of all, kindly look at my design,

I have two tables
T1(a,b,c,d)- a is primary key
T2(a,e) where (a,e) is composite primary key
a is the foreign key referencing T1(a)

T1 - T2 relationship is one to many.

So I created three classes
1. C1 for T1
It has five fields -
a,b,c,d, c2Set with setters & getters

2. C2 for T2
It has two fields- c1,c3 of type C1, C3 respectively- with setters & getters


3. C3 I am defining C3 to represent composite primary key of T2
It has two fields (a,e) with setters & getters

I am using following annotations to define hibernate mappings in classes C1,C2,C3 respectively

1.


2.




3.









I have a problem when I am inserting(saving) data. Data into T1 is getting inserted but no insertion is happening in T2( which I think should happen automatically here) ?
Please tell me where I am doing things wrongly.
And, I want to learn more about Hibernate Annotations. Can anyone point me to some useful online resources.

And, is it good to separate a form bean from entity class?
Please tell me the resources where I can get to learn about design issues like this.

Thanks
Vivek.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate annotations one to many relationship with composite primary key