-->
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: How to set the object class name in a projection?
PostPosted: Tue Sep 12, 2006 8:26 am 
Newbie

Joined: Thu Apr 08, 2004 4:28 am
Posts: 16
Hibernate version: 3.1.3

Name and version of the database you are using: Oracle 10.2.0

If you have an inheritance tree of objects mapped in Hibernate, for example:

Code:
public abstract class BaseClass { }
public class classA extends BaseClass { }
public class classB extends BaseClass { }


When you use criteria to search for all objects of BaseClass, you get as result a list with instances of classA and instances of classB.

But I want to use a projection list in combination with an AliasToBeanResultTransformer. This maps the specified attributes on the attributes of the DTO class specified in the ResultTransformer.
But how can I map the name of the class of the result instance (classA or classB) to the DTO object? I have to know what type it is.

Code:
criteria = session.createCriteria(BaseClass .class);
criteria.setProjection(Projections.projectionList()
                .add(Projections.property("oid"), "oid")               
                .add(Projections.property("year"), "articleYear")
                .add(Projections.property("number"), "articleNumber")
                .add(Projections.property("description"), "description")
                .add(Projections.????????, "className")
);
criteria.setResultTransformer(new AliasToBeanResultTransformer(BaseDTO.class));


Thanks in advance for any help!


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.