-->
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.  [ 4 posts ] 
Author Message
 Post subject: Can't get discriminator value
PostPosted: Wed Apr 05, 2006 8:29 pm 
Newbie

Joined: Wed Feb 15, 2006 7:51 pm
Posts: 9
Location: Sydney, Australia
I've got an entity mapped that's using the table-per-class-hierarchy design. As a result, there's a discriminator column called 'itemtype'. This is all working fine and Hibernate correctly instantiates the appropriate subclass. However, my code needs to be able to directly acess that itemtype property as in: myItem.getItemType(). To do that, I mapped a property separate from the discriminator which doesn't update or insert:
<property name="itemType" column="itemtype" not-null="true" update="false" insert="false" />

Unfortunately, this value doesn't seem to be set by Hibernate until after the object is first saved to the db. But my code needs to be able to get the value at any time (whether or not it has been saved). Is there any way to obtain the value before Hibernate has saved the object?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 05, 2006 10:30 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
In the constructor that your API uses, call the appropriate setItermType method. You have to do it manually, because your requirement is to have it done before hibernate knows that the object exists. There's no hibernate short cut that'll help you.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 06, 2006 7:36 pm 
Newbie

Joined: Wed Feb 15, 2006 7:51 pm
Posts: 9
Location: Sydney, Australia
ok, that's what i figured. But I was hoping there might be a way to 'register' the unsaved object with Hibernate so that it could set the discriminator field. heheh wishful thinking.

thanks for the help


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 06, 2006 9:22 pm 
Newbie

Joined: Tue Jan 04, 2005 4:52 pm
Posts: 13
Hello chipman,

In HQL you can use the .class property to extract the discriminator. Any in java comparisons should be done one the class name or using the instanceof
operator

e.g.

session.createQuery ("select i.class from Item i")

or if (i instanceof SubItem) {}


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