-->
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.  [ 6 posts ] 
Author Message
 Post subject: 1-many mapping
PostPosted: Tue Jun 26, 2007 3:21 pm 
Newbie

Joined: Sun Oct 01, 2006 10:35 pm
Posts: 9
Hi,
I have a master table and details table. they have 1-many relationship from master to details. Details, you can think of as history or different old versions of a record in the master.

Now if we want to have only one class in the domain model, is there any way to map this 1-many relation into one domain class in the domain model. (the regular way being one class for Master and one for Details and using Set to hold details in Master, but we want just one class!)
I found no way to do that using Hibernate.
This is a legacy database and cannot change schemas now.

Any ideas would be greatly appreciated.

Thanks
K


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 26, 2007 3:53 pm 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
It "might" be possible, depends on what the "details" table contain. Let us know more about it and we can explore.

Regards,
Jitendra


Top
 Profile  
 
 Post subject: 1-many mapping
PostPosted: Tue Jun 26, 2007 6:45 pm 
Newbie

Joined: Sun Oct 01, 2006 10:35 pm
Posts: 9
Jitendra,
thanks for responding. Details table is as I said just to hold versions.
Consider a master table called Plan. it has a primary key planid.
Now there is PlanDetails table, which has primary key as (planid, planeffdate) This is required as the same plan (with same planid) can be closed and reopened any number of times over a period of time. So, whenever a plan is closed a corresponding column in the Details table will be updated. Also, when a plan is opened again one more record will be inserted into PlanDetails table, with new Planeffdate (plan effective date). Details table also has lot of other fields.

But in the domain model, we just want to use one class to store both master and details tables. considering its a 1-many relationship how can I creating mapping for a single class. If it is a 1-1 then I could have used <join> tag? Any help would be rated very high!

Thanks
K


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 27, 2007 3:35 am 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
I am still not clear with your details table. Can you give me the column names exactly.

If your table contains more than one column (other than Id) then it will be difficult to map without having another class, since your relationship is 1-to-many and not 1-to-one.

Regards,
Jitendra


Top
 Profile  
 
 Post subject: has more than 1 column
PostPosted: Wed Jun 27, 2007 7:09 pm 
Newbie

Joined: Sun Oct 01, 2006 10:35 pm
Posts: 9
Yes jitendra, my details table has many columns (more than 20) other than primarykey. and it is infact 1- many. I strongly feel it cannot be done with one class, but want to know if any body has any solution.
do think we can do with 1 class?

Thanks alot
K


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 2:02 pm 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
Hibernate is designed to replicate the java object model. How do you represent such a structure in your java app? Whatever it would be, won't be very pretty.

Regards,
Jitendra
*Please do rate if it helps*


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.