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.  [ 2 posts ] 
Author Message
 Post subject: Mapping one class to a set of Tables - possible?
PostPosted: Thu Nov 13, 2008 6:51 am 
Beginner
Beginner

Joined: Thu Oct 04, 2007 12:22 pm
Posts: 48
I want to map one class not to one table but to many ones. In dependency of the programatical case a data entry shall be stored to one of the mapped tables.
For example there is a class Data which shall be mapped to the tables DataTable1, DataTable2, DataTable3. For my case I could imagine a syntax which differs the target of an operation via entity names, perhaps:

Code:
Data dataObj1, dataObj2
...
session.save("DataTable1Entity", dataObj1); // => DataTable1
session.save("DataTable1Entity", dataObj2); // => DataTable2


I assume that this is possible with hibernate but I found nothing to this topic except a forum post indicating that this feature is limited to Hibernate 3.x.
Is it possible to do so?


As workaround I created a class hierarchy for the needed types even if they do not differ in any attribute except the mapping target - like:
Code:
Data1 extends Data // maps DataTable1
Data2 extends Data // maps DataTable2


As inheritance strategy my choice was "one table per concrete class". But this has a side effect, I would like to avoid:
If the superclass declares its primary key as GeneratedValue it seems that the subclasses share the value space of the generated keys. I was forced to set the generator from "native" to "hilo" introducing a unique key table. Is it not possible to delegate the key generation to each table, so that they are responsible for creating their keys?

Hibernate version:
3.3
Database:
MySql 5


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2008 8:52 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
I assume that this is possible with hibernate but I found nothing to this topic except a forum post indicating that this feature is limited to Hibernate 3.x.
Is it possible to do so?


http://www.hibernate.org/hib_docs/v3/re ... yname.html


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