-->
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: Inheritance and specialisation
PostPosted: Wed Nov 01, 2006 6:14 pm 
Newbie

Joined: Wed Nov 01, 2006 6:01 pm
Posts: 2
Is it possible to change an object's class from a generalised form to a specialised form without changing the identifier?

I have two classes, a Dog and an Animal. A Dog extends Animal. I am currently using joined table inheritance.

At initial data entry time, all I know is that I am importing animals. An animal object is created and saved to the database. Then, various objects of other classes link to the animal. Finally, I find out that the animal is really a dog, so I want to change the specialise the object.

What I have tried is to implement a constructor to Dog that takes an Animal as a parameter. This copies all the attributes, including the identifier. However when I call saveOrUpdate, I get a StaleObjectException.

I accept that what I am trying to do in Java terms is impossible - as the construction process would create a new object, and any list of objects that had been previously created would still contain a reference to the original identifier. However it is something that can be done in SQL world by creating a new row in the joined table.

Is this possible or am I trying to do something really stupid. My alternatives appear to be to either create a new persistent object, find all references to the original one and move them over, and then delete the original object, all within the same transaction; or remove the inheritance and let a Dog contain an animal as a property.

Thanks

alan


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.