-->
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.  [ 5 posts ] 
Author Message
 Post subject: Load object state into a unmapped subclass
PostPosted: Wed Oct 20, 2004 4:14 pm 
Newbie

Joined: Tue May 11, 2004 10:47 am
Posts: 16
Hibernate 2.1.6

Hi, I have a class A which is persistent (eg, entered in an hbm.xml file). I have a class B which is subclass of A, but is not persistent (not in an hbm.xml file). Can I load the state of an instance of A into an instance of B?

I'm trying to do

Code:
B b = new B();
Serializable aId = // ID of a persistent instance of A.
session.load(b, aId);


but of course I get

net.sf.hibernate.MappingException: No persister for: B

So, I'm looking for something that would work like session.load(Object, Serializable), but would maybe also take the persistent class of the object to load, like

Quote:
session.load(Class cls, Object o, Serializable id)


which would work provided o is a subclass of cls. Does this functionality exist?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 20, 2004 5:21 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
take a look at "select new b(a.x,a.y) from a where..."

search projection in the reference guide

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


Top
 Profile  
 
 Post subject: What about the other direction.
PostPosted: Tue Nov 23, 2004 12:50 pm 
Newbie

Joined: Wed Nov 17, 2004 12:41 pm
Posts: 2
We have a similar situation.

Based on the above example, how do we persist changes to B?

We get a
Code:
MappingException: No persister for: B
.

How can we achieve persistence for B without mapping B seperately or using a discriminator?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 12:54 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
b isn't mapped....

if you want to persist it, just map it...

sounds strange you use select new() to instanciate transcient mapped objet and then want to persist it... but why not, some kind of copy function

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


Top
 Profile  
 
 Post subject: Thanks.
PostPosted: Wed Nov 24, 2004 2:50 pm 
Newbie

Joined: Wed Nov 17, 2004 12:41 pm
Posts: 2
Thanks. We did decide to map our situation slightly diffierently, and everything worked out.


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