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