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.  [ 3 posts ] 
Author Message
 Post subject: Conditional Mapping
PostPosted: Tue Jun 28, 2005 4:37 pm 
Beginner
Beginner

Joined: Tue Jun 28, 2005 4:33 pm
Posts: 21
Not sure if this is possible with hibernate, but....

I have one object, that depending on its state, can map to two different tables. Is there a way to have two mapping files for one object, and conditionally pick which one to use based on a flag in the object?

Thanks.


Top
 Profile  
 
 Post subject: Re: Conditional Mapping
PostPosted: Tue Jun 28, 2005 5:47 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
mjstein6300 wrote:
Not sure if this is possible with hibernate, but....

I have one object, that depending on its state, can map to two different tables. Is there a way to have two mapping files for one object, and conditionally pick which one to use based on a flag in the object?

Thanks.


I think you need to be a little more clear on what you're trying to do.

But if I understand you correctly..... To map one Class to 2 different tables, see the <class> attribute "entity-name" in the documentation.

Then, since you have 2 separate mappings, you would need to query the objects by the specified entity-name. I believe you would also need to specify this entity-name when you persisted the objects.

You can also map 2 Objects to 1 table using a discriminator and based on the value of this, two different objects would be created. But I don't think that's what you're asking for.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 29, 2005 8:59 am 
Beginner
Beginner

Joined: Tue Jun 28, 2005 4:33 pm
Posts: 21
Thanks, the entity-name may be just what I need. Unfortunately, we're using 2.x on the project, so now there's a human engineering problem to work out.

To further explain what I need... This is a reengineering of a functional project, and they don't want any database changes. I have a POJO that goes through multiple states (ie; pending, active, and complete). Currently, the data is stored in different tables depending on the state (something I can't change). Since it's the same information, the hope was to have one object, and depending on it's state, have different mappings. The alternative was to have mulitple objects, which would make maintenance more difficult down the line.


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