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?