Hi,
I would like to get back partially valuated object form DB. Say I want a Person instance but without all its attributes valuated. Some attributes (valuated or not) may be simple @Basic, but may also be relation like @ManyToOne, ... This is like in plain old SQL where one try to get only useful columns rather than Select * but this is also a way to accept or "cut" relations to restrict what come back from DB.
The only way I found to do that is using request and give the list of wanted only attributes after the SELECT or using Criteria query API.
Unfortunately, in both cases, I get back with an array of hash tables instead of a List<Person>.
Very important note : this should be dynamic and then, can't rely on annotation. That's why I can't use eager or lazy loading feature to do that, because lazy loading is static. If you tag eager or lazy one field, not only this will be "forever" but also doesn't make sense for @Basic fields. There is a solution with query than involve constructor but it is not possible : constructors are not dynamic. Basically, depending on business rules and end user behavior, I want the Person with only name and first name, then for another user, I want Person with name, first name and all addresses, then ... All that happen at run-time. I can build the query string at run-time without problem, but I can't build a constructor at run-time, and also I can't develop all the constructors combination !
Question 1 : is it doable ?
Question 2 : is there other solutions ?
The problem I have with hash tables is that all meta information are gone. I might be able to deal (with some heavy works) with hash table where the key is the attribute name, but provided hash tables keys are the position inside the SELECT clause.
Thanks for your help!
|