-->
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: Lazy property with projections
PostPosted: Thu Oct 27, 2011 6:39 pm 
Newbie

Joined: Fri Apr 29, 2011 3:21 pm
Posts: 6
Hello everybody.

If you have your bean MyClass whit alot of properties.
If you want to lazy get one property with @Basic( fetch=lazy ) you need to instrument your class right?.

but

what if you do a projection over your bean and then do a ResultTrasnformer(TransFormers.aliasToBean(MyClass.class))

something like this:

Usuario usuario = (Usuario) session /*.get(Usuario.class, 1); this gets the whole object with out @Basic(fetch=lazy)*/
.createCriteria(Usuario.class)
.add(Restrictions.eq("id", 1))
.setProjection(Projections.projectionList()
.add(Projections.property("id").as("id"))
).setResultTransformer(Transformers.aliasToBean(Usuario.class))
.uniqueResult();

That do the trick. You got only the ID and not the whole object.

My question is. This Object of Usuario is the same in the query cache as if i get it with .get()?

Thank you.


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.