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: joined-subclass and getting sub-class
PostPosted: Tue Jun 07, 2005 6:59 am 
Beginner
Beginner

Joined: Tue Apr 05, 2005 12:09 pm
Posts: 48
Location: Slovakia (SK), Košice (KE)
Hibernate version: 3

Hello. How can I session.load() a concrete subclass if I know the ID and not the concrete subclass? I use Table per subclass mapping.

I have 3 classes: Widget (abstract superclass) and subclasses WidgetPicture and WidgetLine.

Code:
Widget widget = (Widget) session.load(Widget.class, id);
// now widget contains proxy class and it can't be retyped to a concrete subclass
// this (ugly) hack will retrieve the correct subclass:
Widget widget = (Widget) session.load(session.getEntityName(widget), id);


The second line moreover generates a warning:
Code:
WARN  PersistenceContext - Narrowing proxy to class com.kovine.kfe.dao.WidgetPicture - this operation breaks ==


So, what I need is to load a concrete subclass but I know only the ID, not the concrete subtype. I've found in the hibernate forums similar problems, but not one solving this issue.

Gurus, please help me and you'll get to the heaven :)
Martin


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 7:02 am 
Beginner
Beginner

Joined: Tue Apr 05, 2005 12:09 pm
Posts: 48
Location: Slovakia (SK), Košice (KE)
fix: second line doesn't contain declaration (of course):
Code:
Widget widget = (Widget) session.load(Widget.class, id);
widget = (Widget) session.load(session.getEntityName(widget), id);


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 8:09 am 
Beginner
Beginner

Joined: Tue Apr 05, 2005 12:09 pm
Posts: 48
Location: Slovakia (SK), Košice (KE)
Code:
<hibernate-mapping default-lazy="false">
helped, but I'd like to have my class lazy. Pls help.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 9:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
use get or a query.list() but you can still get the issue if you have already loaded the "non-castable" proxy before in the session.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 9:25 am 
Beginner
Beginner

Joined: Tue Apr 05, 2005 12:09 pm
Posts: 48
Location: Slovakia (SK), Košice (KE)
Thanks max! It works. Unfortunately I can't find this feature in the documentation (only http://www.hibernate.org/hib_docs/v3/reference/en/html/objectstate.html#objectstate-loading) but nevermind.
Please look at the http://forum.hibernate.org/viewtopic.php?t=943445 yet.

--
Martin


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.