-->
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.  [ 1 post ] 
Author Message
 Post subject: HSQL: Reading the class name in a polymorphic query
PostPosted: Mon Jun 14, 2010 12:27 pm 
Newbie

Joined: Mon Jun 14, 2010 12:06 pm
Posts: 1
Lets say I have 3 very complex Java classes (ClassA, ClassB, ClassC) with some inheritance:
ClassC extends ClassA
ClassB extends ClassA


I want to obtain the identifier of a set of objects and the class of this objects:

for(ClassA element: getSession(false).createQuery("from ClassA where ...").list() ) {
doSomeProcessWith( element.getClass(), element.getId() )
}

Because I have really complex objects, this HQL query causes a heavy database query (complete ClassA objects and inheritance solving causes complex queries).

Then I try this alternative query (causing a really simple sql query)

for(Object[] element: getSession(false).createQuery("select class, id from ClassA where ...").list() {
doSomeProcessWith( element[0], element[1] )
}

The problem here is Hibernate solves "class" as an integer value (the class discriminator in a polymorfic query)

¿Is there any way to obtain the Java Class as a result in HQL?
¿Is there any way to traslate the HQL polymorfic discriminator in a Java Class object?

Thanks a lot


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.