-->
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: MappingException when saving nonpersistent subclass
PostPosted: Sat Dec 15, 2007 3:22 pm 
Newbie

Joined: Sat Dec 15, 2007 2:47 pm
Posts: 1
Hi there,

I have a persistent class eg.orm.A with a nonpersistent wrapper subclass eg.bl.AWrapper, which I created to contain business logic methods and some (nonpersisted) fields. When I try to save an instance of the subclass as follows:

Code:
Session s = util.getSessionFactory().openSession();
AWrapper w = new AWrapper();
w.calculateFieldValues(); // sets values of inherited persistent fields
s.save(w);
s.close();


I get
Code:
org.hibernate.MappingException: Unknown entity: eg.bl.AWrapper
. This happens even if I try to cast it to the mapped superclass A.

In the past I've gotten around this problem by having AWrapper encapsulate rather than extend A. In this case, though, A has so many fields that I'd rather not if I can avoid it. I don't want or need to make AWrapper persisent.

Any suggestions?

Thanks in advance,
Eric


Top
 Profile  
 
 Post subject: MappingException when saving nonpersistent subclass
PostPosted: Sat Jan 19, 2008 11:41 am 
Newbie

Joined: Sat Jan 19, 2008 11:32 am
Posts: 2
Hi,


I've solved this issue in the past by using the "Table per class hierarchy" inheritance mapping.

See: http://www.hibernate.org/hib_docs/v3/re ... leperclass

For your example you will have to create another column in your database with a unique value for each class that you want hibernate to map and will have to add some lines to your mapping file but after that you will have a clean biz object (won't have all the setters and getters) that you can toss over to hibernate to put into the db for you.

If you want some sample code let me know and I'll try to get some time to post some.

BTW: This seems like a hack but it worked for me.

Joe


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.