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.
|