• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Hibernate annotations one to many relationship with composite primary key

Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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




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.


No more fooling around. Read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
    Bookmark Topic Watch Topic
  • New Topic