-->
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.  [ 4 posts ] 
Author Message
 Post subject: table-per-subclass question
PostPosted: Tue Feb 22, 2005 3:29 pm 
Newbie

Joined: Tue Feb 22, 2005 3:22 pm
Posts: 2
Hi all, I have a question on what happens with table per subclass mappings And i hope you can all help.

What i need to do is simple, i need to have a class A and a Class B that extends A, simple enough, but what i need to happen is i need to be able to declare and use Class A and persist it, then at some point i need to turn class A into class B so i can have access to more information and yet maintain what i already had.

How is this accomplished in reality, is it a special mapping of any kind, is it all code based in transforming? do you have to create a new instance of B and copy A over then kill A?

The goal is to not have duplicate info, im just curious as to how this transformation can happen, any input is very welocme, and thanks in advance.......


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 22, 2005 3:58 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
i need to turn class A into class B


just forget persistence stuff and focus on java.... not really easy.
Have in mind that this is a conceptual problem, you should has used delegation better than inheritance.

the best you have to do is to search the forum, this has been discussed many times.

you have 2 choices:
- deep copy
- jdbc update + reload entity

but don't reply here, let's search on the forum

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: you can do this with the table per heirarchy strategy
PostPosted: Tue Feb 22, 2005 4:16 pm 
Newbie

Joined: Tue Jan 04, 2005 4:52 pm
Posts: 13
I ran into a similiar problem. I have two kinds of clients that do some of the same things and some different ones to my object model.

My heirarchy:
Code:
BaseModelData
^                    ^
|                     |
ClientOne      ClientTwo
   Data              Data



I wanted to load the client specific data when the model was sent client side.

What I did to make this work is to employ the table per heirarchy strategy but to set the discriminator to a constant for all the subclasses.

What this allows me to do is

Save a ClientOneData instance and read it back as a ClientTwoData instance. There should be problems if you have an instance of ClientOneData and one of ClientTwoData that refer to the same BaseModelData class active at the same time in the same session.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 22, 2005 5:56 pm 
Newbie

Joined: Tue Feb 22, 2005 3:22 pm
Posts: 2
Kastor, Thank you very much for your reply, i have seriously been thinking of just using table per heirarcy instead, since class B is purely a subclass of A, and there are no others, its just a simple extension and i should be able to change the descriminator when i need to and do any cleanup i might need to do.

I guess ill give it more thought before i impliment and hope anyone else with perhaps a more solid approach makes it known, otherwise its a solution between you, I, and the search lol......


And to the first poster, theres no need to be rude, im not 2 years old, i used the search, it didnt yeild what i was looking for which is conceptual, if you can find ANY search engine that can truely answer a conceptual question without getting lucky then let me know, we can both buy stock in it and be rich.......


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