-->
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: Single class with 2 mappings
PostPosted: Thu Apr 22, 2004 4:47 pm 
Newbie

Joined: Tue Sep 02, 2003 9:47 am
Posts: 8
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 26, 2004 2:19 pm 
Newbie

Joined: Thu Apr 22, 2004 3:21 pm
Posts: 15
We had a similar problem to solve as you. Our problem was we had a Versioned bean for every bean in the system.

What we did is had two instances of Hibernate (sharing the same datasource). So if we wanted the real bean we would get hibernate1, if we wanted a list of all the versioned beans we would go to hibernate2.

We chose this solution because we would rather have one java class and two mapping files, rather than messing with our class diagram to make hibernate work!


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.