-->
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.  [ 5 posts ] 
Author Message
 Post subject: Join with Projections
PostPosted: Tue Nov 28, 2006 9:48 am 
Newbie

Joined: Tue Nov 28, 2006 9:34 am
Posts: 15
Location: Brasil
I'm trying to use Projections to bring only what i need...
But now i just need to bring the Id, Description and the Parent Description...

From a table like this example:
Table TpDoc:

int PkTpDoc
int FkTpDoc
varchar(50) DescTpDoc
manymanyotherfieldshere...

(This FkTpDoc points to PkTpDoc)

How can i do it without using HQL and creating a constructor in the class TpDoc??

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 10:59 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
You want to use Criteria queries to project?

http://www.hibernate.org/hib_docs/v3/re ... projection

Or perhaps I'm not understanding your question.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 12:57 pm 
Newbie

Joined: Tue Nov 28, 2006 9:34 am
Posts: 15
Location: Brasil
Actually the criteria.createAlias already worked for me... Now i'm trying to Transform the result into my object...

My code:
Code:
Criteria c = getSession().createCriteria(myclass);
ProjectionList pl = Projections.projectionList();
c.createAlias("tpDoc", "tpDoc", CriteriaSpecification.LEFT_JOIN);
pl.add(Projections.property("pkTpDoc"), "pkTpDoc");
pl.add(Projections.property("descTpDoc"), "descTpDoc");
pl.add(Projections.property("tpDoc.descTpDoc"), "tpDoc.descTpDoc");
c.setProjection(pl);
c.setResultTransformer(new AliasToBeanResultTransformer(myclass));

This projection alias "tpDoc.descTpDoc" doesn't work... :(

Any suggestions?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 1:41 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Let's try this:

Code:
Criteria c = getSession().createCriteria(myclass, "child");
ProjectionList pl = Projections.projectionList();
c.createAlias("tpDoc", "parent", CriteriaSpecification.LEFT_JOIN);
pl.add(Projections.property("child.pkTpDoc"), "pkTpDoc");
pl.add(Projections.property("child.descTpDoc"), "descTpDoc");
pl.add(Projections.property("parent.descTpDoc"), "parentDescTpDoc");
c.setProjection(pl);
c.setResultTransformer(new AliasToBeanResultTransformer(myclass));


I've not used the ResultTransformer in a while, but I'll assume that's coded right for now. :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 2:12 pm 
Newbie

Joined: Tue Nov 28, 2006 9:34 am
Posts: 15
Location: Brasil
No... :(
Code:
Could not find setter for child.pkTpDoc on class test.TpDoc


But thanks...


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