-->
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: Getting Class name from HQL discriminator value?
PostPosted: Sat Nov 21, 2009 1:45 pm 
Newbie

Joined: Tue Apr 12, 2005 4:13 pm
Posts: 3
Using Hibernate 3.3 on Oracle 10g, I have the following Criteria -

Code:
Criteria c = HibernateUtils.getCurrentSession().createCriteria(DataObject.class)
   .setProjection(Projections.distinct(
      Projections.projectionList()
         .add(Projections.id())
         .add(Projections.property("name"),"name")
         .add(Projections.property("description"),"description")
         .add(Projections.property("class"), "className")
    ))
   .add(Restrictions.in("id", ids))
   .addOrder(Order.asc("name"));
         
   List<DataObjectProxy> objects =
      c.setResultTransformer(Transformers.aliasToBean(DataObjectProxy.class)).list();

Basically, I want to get the name of the subclass into a property of the DataObjectProxy class. DataObject is an abstract class with 4 joined-subclasses.

The criteria generates the following SQL (which runs fine):
Code:
select
        distinct this_.id as y0_,
        this_.NAME as y1_,
        this_.DESCRIPTION as y2_,
        case
            when this_1_.id is not null then 1
            when this_2_.id is not null then 2
            when this_3_.ID is not null then 3
            when this_4_.ID is not null then 4
            when this_.id is not null then 0
        end as y3_
    from
        T_OBJ_DATA this_
    left outer join
        T_OBJ_DOMAIN this_1_
            on this_.id=this_1_.id
    left outer join
        T_OBJ_RESOURCE this_2_
            on this_.id=this_2_.id
    left outer join
        T_OBJ_INITIATIVE this_3_
            on this_.id=this_3_.ID
    left outer join
        T_OBJ_DASHBOARD this_4_
            on this_.id=this_4_.ID
    where
        this_.id in (
            ?
        )
    order by
        y1_ asc

How do I get a useful value from the discriminator values in the case stamenent? The class property returns an integer that relates to one of the joined-subclasses?


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.