Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate one to many mapping

 
Nrapendra Sharma
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • 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
>
 
Ankit Garg
Sheriff
Posts: 9580
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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..
 
sudha swami
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Ankit said, it is possible.
Sudha
 
Ankit Garg
Sheriff
Posts: 9580
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic