-->
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: Inheritance: Change an instance's class
PostPosted: Thu Nov 29, 2007 5:11 pm 
Newbie

Joined: Wed Mar 28, 2007 7:57 am
Posts: 3
Hi,

I've got two classes like Car and Bike which both inherit from Vehicle and are stored using a single table strategy.

Now I would like to change the class of a persistent object without changing its id. Yes, I do have a need for that :-)

In plain database terms it would mean to modify the discriminator field's value for that row (and perhaps some fields representing the instance's properties).

But is there a way to do that in Hibernate?

I've tried to turn a bike into a car with some code like this:

//retrieve bike from database
...

id = bike.getId();
entityManager.clear();

car = new Car();
car.setId(id);
entityManager.merge(car);

But that just creates a new car without caring about the id I set.

Any ideas appreciated!

Norbert


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 30, 2007 6:26 am 
Beginner
Beginner

Joined: Thu Nov 02, 2006 9:38 am
Posts: 32
Location: Belgium
I doubt you can do this, because Java doesn't allow it. You'll have to take care of it outside of a hibernate transaction.


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.