Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

hibernate one to many mapping

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have done following mappings in my model...



Attendee table follow table class and has two subclasses MainAttendee and SubAttendee.

MainAttendee is always one and SubAttendee can be multiple
I want to know whether it is possible in hibernate that i define two variables in Meeting class one for MainAttendee and other for collection of SubAttendee.
something as follwing :::::



i want a single relationship as MainAttendee and SubAttendee are member of same table..
Is it possible ???

Regards,
Nrapendra
>
 
Sheriff
Posts: 9691
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I think you can do that. You can create a one-to-one relationship with MainAttendee and a one-to-many relationship with SubAttendee...
 
Nrapendra Sharma
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ankit,
Thanks for your reply.
Actually i want single mapping between meeting and attendee table
if i do one to one with MainAttendee and one to many with SubAttendee then i think there will be two mappings between Meeting and Attendee Table as MainAttendee and SubAttendee are part of one table..
 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Ankit said, it is possible.
Sudha
 
Ankit Garg
Sheriff
Posts: 9691
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nrapendra Sharma wrote:if i do one to one with MainAttendee and one to many with SubAttendee then i think there will be two mappings between Meeting and Attendee Table as MainAttendee and SubAttendee are part of one table..



So what's the problem with that?? You are allowed to do so...
 
Nrapendra Sharma
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By doing things as you said things will work but in database level there are two relationships between meeting and attendee table..
There will be two relationships
Meeting-MainAttendee
Meeting-SubAttendee

According to me this thing is not optimized as far as database is concerned because foreign key is primary key is same for both relationships.


reply
    Bookmark Topic Watch Topic
  • New Topic