-->
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: HQL: ".class" implementation...
PostPosted: Thu Jan 20, 2005 1:47 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:12 am
Posts: 39
hi hg,

just looking for some clarification on the implementaion of using ".class" in hql. After much searching i finally discovered that this notation requires the actual discriminator value in the query and not the class object that you want to search for. Since you don't have\need the discriminator value in java code why can't hibernate perform this mapping for us so that we don't even need to know about the discriminator?

Let me give you an example of how useful this would be, i have a dao method for finding all objects of a certain subclass which requires the class of object. here is what i would like to do:
Code:
public List listFixedCodes(Class fixedCodeType){
       return getSession().find("from FixedCode as f where f.class = ?", fixedCodeType, Hibernate.CLASS);
}


Instead i either have to maintain a map of classes to discriminator values or do string manipulation using the class name, eg:
Code:
public List listFixedCodes(Class fixedCodeType){
       return getSession().find("from FixedCode as f where f.class = ?", lookupDiscriminator(fixedCodeType), Hibernate.STRING);
}


or

Code:
public List listFixedCodes(Class fixedCodeType){
       return getSession().find("from " + fixedCodeType.getName());
}


I thought that Hibernate wanted to hide implementation details from the user, a discriminator value has no use in java and as far as i am concerned should never be referenced outside of the mapping files.

Comments?

cam


Hibernate version: 2.1.5


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 21, 2005 10:43 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
well actually you can do weird stuffs like .class like '%blah%'

_________________
Emmanuel


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.