-->
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: Projections and its joining associated objects
PostPosted: Mon Feb 26, 2007 3:34 am 
Newbie

Joined: Mon Feb 26, 2007 2:58 am
Posts: 3
Hi,

I am new to Hibernate.
I need to do several left joins using the Hibernate Criteria API.

What I would like to do is to get a list of objects (document) without retreiving all the attributes of the objects using projection. Meanwhile, each object has an associated object (invoice) with all its attributes needed.

Here is my work I have so far for one of my problems:
Criteria criteria =
session.createCriteria(Document.class, "document")
.setProjection(Projections.projectionList()
.add(Projections.alias(Projections.property("documentType"), "documentType"))
.add(Projections.alias(Projections.property("dateUploaded"), "dateUploaded"))
.add(Projections.alias(Projections.property("invoice"), "invoice"))
.add(Projections.alias(Projections.property("invoiceNumber"), "invoiceNumber"))
.add(Projections.alias(Projections.property("remarks"), "remarks")))
.createAlias("document.invoice", "invoice", CriteriaSpecification.LEFT_JOIN)
.addOrder(Property.forName("dateUploaded").asc())
.setResultTransformer(new AliasToBeanResultTransformer(Document.class));

return criteria.list();
}

The result of it is not what I would like to see. The invoice table is left-joined but its attributes are not queried.
I would like the invoice to be queried as an (associated) "full" object of the "partial" document object.
Please help!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 26, 2007 10:39 am 
Newbie

Joined: Fri Apr 22, 2005 3:39 pm
Posts: 18
What do you mean that your invoice is not queried? You mean you get proxies?

Try
Code:
.setFetchMode("invoice",FetchMode.EAGER)

instead of
Code:
.createAlias("document.invoice", "invoice", CriteriaSpecification.LEFT_JOIN)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 27, 2007 2:25 am 
Newbie

Joined: Mon Feb 26, 2007 2:58 am
Posts: 3
>> What do you mean that your invoice is not queried?

The invoice table is appropriately left-joined with the listed document attributes, but the fields in the invoice table are not queried in my above work.

And the result of .setFetchMode("invoice", FetchMode.EAGER) is identical to my above work. So this does not produce what I need.

Thank you for trying to help ~


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.