-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to map a dinamically generated query
PostPosted: Mon Jun 26, 2006 9:41 am 
Beginner
Beginner

Joined: Thu Jun 30, 2005 5:15 am
Posts: 21
Hi,

I'm trying to map the result of a query to a value object. The query returns mainly aggregates and there is no object with the proper XML for it.

A solution would be to create a view in the database and then map it directly to the object (using the standard mapping files) but, since creating a view might not be allowed in our project, I'm looking for another way to do this.

Do you know how you can map the result of a query that returns agreggates to a bean object with just the properties for the columns returned ? The idea is to avoid using lists, which are error-prone, and use instead a formal value object.

Any comments would be really welcome.

Regards,

- Juancho


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 26, 2006 7:07 pm 
Newbie

Joined: Tue Apr 25, 2006 3:41 pm
Posts: 3
Location: Redmond, WA
Use AliasToBeanTransformer to map result to a Bean Object. While creating the query, do create an alias which corresponds to Bean property.

Eg: You bean class name: xyz.java
Attributes in bean class : maxCount, maxResults

Criteria c = session.createCriteria(xyz.class,"xyz");
ProjectionList projectionList = Projections.projectionList();
projectionList.add(Projections.property("dbmaxCount", "maxCount");
projectionList.add(Projections.property("dbmaxResults", "maxResults");
c.setProjection(projectionList);
criteria.setResultTransformer(new AliasToBeanResultTransformer(xyz.class));
List l = c.list();

This will give you xyz object with the properties set.

Thanks,
Ram


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 6:59 am 
Beginner
Beginner

Joined: Thu Jun 30, 2005 5:15 am
Posts: 21
That's exactly what I was looking for.

Thank you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.