-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Does hibernate support one child table - many parent tables
PostPosted: Wed Jun 11, 2008 2:03 pm 
Newbie

Joined: Wed Oct 12, 2005 11:16 am
Posts: 13
Hi

We have two tables "Company" and "Person" as follows:

Company
[
CompanyId int PK
Name varchar
]

Person
[
PersonId int PK
FirstName varchar
LastName varchar
Type varchar
TypeId int
]

If Person.Type ="Company", then the Person details are for the Company whose Id is the value of Person.TypeId

This way a child table (Person) can have multiple parents based on the values of Type and TypeId.

Is there a way to achieve this in hibernate. We are using hibernate3.2, MySQL5, Java1.6 and Tomcat6.

Thank you for your help in advance

Regards

Sri


Last edited by sridharrajup on Thu Jun 12, 2008 9:55 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 11, 2008 4:22 pm 
Newbie

Joined: Tue Apr 29, 2008 1:42 pm
Posts: 12
Have you figured out your Java classes?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 11, 2008 5:14 pm 
Newbie

Joined: Wed Oct 12, 2005 11:16 am
Posts: 13
Hi

Java classes would be generated by hibernate tools and they look almost same as the table definitions with getters and setters.

Thanks

Sri


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 12, 2008 8:32 am 
Newbie

Joined: Wed Oct 12, 2005 11:16 am
Posts: 13
Hi

Can any one help me with this problem?

Thanks

Sri


Top
 Profile  
 
 Post subject: similar problem
PostPosted: Thu Jun 12, 2008 10:56 am 
Newbie

Joined: Thu Jun 12, 2008 10:40 am
Posts: 1
Have you found an answer yet? I have a similar problem. Two parents, one child; but in table use only. The child only ever has one parent, but it may be one of many. For example....

SalesFile
[
id int PK
data varchar
]

ServiceFile
[
id int PK
data varchar
]

ContactFile
[
id int PK
name varchar
otherdata varchar
type varchar
typeId int
]

And when I need to have contact info for the SalesFile record I will have a ContactFile.type of "SalesFile" and set ContactFile.typeId to SalesFile.id and do the same type of thing when I need contact info for ServiceFile records. I am not able to figure out how to map this in Hibernate so that it will produce the proper/expected relationships between the tables. Any and all help would be appreciated. Is this similar to your situation?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 12, 2008 11:08 am 
Newbie

Joined: Wed Oct 12, 2005 11:16 am
Posts: 13
stevenhillsr

Mine is exactly the same situation as yours. I am trying to get to the parent from child based on the values of "Type" and "TypeId" fields in the child.

I looked at many forum threads, hibernate doc and no where I could find a similar scenario being used.

There was one solution based on "discriminator" attribute but this would be a column in parent table and based on its value it points to the appropriate child.

But the scenario you and me are looking at is different and it is the other way.

I hope some one would reply with a solution to this problem.

Thanks

Sri


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 12, 2008 5:12 pm 
Regular
Regular

Joined: Thu Aug 28, 2003 2:42 pm
Posts: 77
Location: The Netherlands
Hmmmm... Maybe an idea to re-design your approach....
Especialy if you can't find a lot about it, it might be an idea th change something more familiar.
Have a look a the hibernate book above as it has some nice design advice, also about using the discriminator.

If you really want to stick to your java-design solution, you can easily transform it to hibernate config, and then simple solve it in code and hibernate queries....


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 13, 2008 5:17 pm 
Newbie

Joined: Wed Oct 12, 2005 11:16 am
Posts: 13
I could find use of "any" attribute for this scenario. But could not find much documentation. Still trying to make it work.

Sri


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.