Hi,
I am not expecting this to be possible, but does anyone know if there is a way of having a single class with 2 different mappings pointing to different tables.
Essentially, I have 2 tables with exactly the same properties but each has a foreign key to other different tables. This works out for example, as a parent object of type A which can have any number of C's, and a different type of parent object B which can also have any number of C's.
I don't really want to combine the data for type C into one table, as that would always leave one of the foreign keys null depending on which parent object the data related too.
I would also like to model this with a single class (as the behavior otherwise is identical), so I was wondering if there is a way of letting Hibernate know which class it is dealing with, and therefore which table to work with.
One way of solving this would be to have an abstract class with all the
functionality and properties, then 2 simple classes which extend this, each with their own mapping file to the different tables. There is nothing wrong with this, as I can hide the implementation of this from the client API and let Hibernate work out which class is which when it has to do something. However, if there another way around this which doesn't involve creating extra classes which could be viewed by a client API, it would be better suited to us.
Note that I manage the relationship between the parent objects and the child objects myself. I can't use Hibernate to manage this, as the data is being lazy loaded, and as I am serialising all of this over RMI, I have to release the session.
Any suggestions would be appreciated. Thanks.
|