-->
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.  [ 4 posts ] 
Author Message
 Post subject: Defining Mapping in Hibernate
PostPosted: Fri Feb 25, 2005 1:31 pm 
Newbie

Joined: Fri Feb 25, 2005 12:53 pm
Posts: 3
Hi,

I am new to Hibernate and would appreciate any insight into my problem.

Description:
--------------
Given the following tables and their columns:

Table_1 (id, name)
Table_2 (id, name)
......
Table_X (id, name)
Generic_Table (table_name, instance_id, status_id)
Status_Table (sid, svalue)

Generic_Table.instance_id could be table1.id or table2.id ....... tableX.id and table_name is the name of table of the corresponding instance_id.
Each table has a status associated to it via the Generic_Table.

Example:
-----------
Let's say we have in Status_Table:
sid = 1
svalue = 'deliver'

sid = 2
svalue = 'cancel delivery'


We insert into Table_1 some values:
Table_1.id = 103 ,
Table_1.name='pizza'

Therefore in Generic_Table we would have:
table_name= Table_1 ,
instance_id = 103 ,
status_id = 1 // which is deliver

Suppose we want to cancel the delivery of the pizza , we would want:

Generic_Table:
table_name= Table_1 ,
instance_id = 103 ,
status_id = 2 // which is CANCEL DELIVERY

Question:
------------
How would we define the relationship mapping in *.hbm.xml between the tables and the Status_Table via Generic_Table in order to create, update, read and delete?


Thank you very much!

-Deep


Top
 Profile  
 
 Post subject: Re: Defining Mapping in Hibernate
PostPosted: Fri Feb 25, 2005 2:08 pm 
Regular
Regular

Joined: Thu Dec 18, 2003 2:14 am
Posts: 103
Location: Brooklyn, NY
This doesn't look like a good design to me, keeping the table name of the foreign reference in a column. Will there really be X number of tables? What use case is this solving? I suggest thinking again about the complexity of this solution.

It seems to me one table would work for all of those X number of tables: just use a column to distinguish the row types. Then you can use that column to refer to another table containing the type definitions. Still dynamic, but much simpler.

Would that help?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 25, 2005 3:42 pm 
Newbie

Joined: Fri Feb 25, 2005 12:53 pm
Posts: 3
Hi Mgreer,

Thanks for responding so quickly!
For our purposes, the design I mentionned is ideal. In fact, Hibernate Demo Application also implemented the same design for logging.

Thanks again
-Deep


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 25, 2005 6:05 pm 
Regular
Regular

Joined: Thu Dec 18, 2003 2:14 am
Posts: 103
Location: Brooklyn, NY
deepk wrote:
Hibernate Demo Application also implemented the same design for logging.

I don't know which demo application this is, but it seems unlikely to me that their database design looked like this. Could you point me to it? If I am wrong, and it does, why not just follow that mapping strategy?

I guess my point is, if your design looks like it is "new" and complicated to implement, than it is worth looking at again. Most needs can reuse tested solutions.

I don't know how you could map this. Maybe someone else does.

Good luck.


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