-->
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.  [ 1 post ] 
Author Message
 Post subject: One type that maps to two different tables?
PostPosted: Sun Nov 27, 2011 8:24 pm 
Regular
Regular

Joined: Wed Jan 21, 2009 8:41 pm
Posts: 54
So I have table A and hibernate needs to poll this table and return objects that map to the columns of A.

Later in the program an error needs to be created and the error is simply an A but it has an additional 2 attributes.

Now I can use native SQL to build the SQL used to poll vs insert depending on the context I'm in but otherwise how can I have one type that's contextual in so far as I can map it's content to one table when selecting but another when inserting?

I don't want to have to create an instance of B and copy the A into B at run time just because I need to have a type B that maps to table B when all I need is to add an additional 2 attributes to my existing A instance and write it to the table that's essentially mapped to B.

The key difference b/w tables A and B is that table A does not have the additional attributes so the generated SQL cannot reference those attributes. Perhaps just a type that's mapped to both A and B but when it's used in context A the select SQL is custom and doesn't include the additional 2 columns?

....

Can all of the above be done more declaratively?

If I had an A and a subclass of A called B how can I persist an A in table B without having to copy all attributes into a newly created instance of B?

It sounds like I should have one type and used custom sql depending on the context I'm doing things. but that's almost identical to the existing approach that would build native sql to match the type of operation that is happening.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.