Hibernate ResultTransformer with addEntity - what's the correct syntax?
Consider the following query:
"SELECT a.code as code,{locFrom.*} " +
"FROM audit.auditlogrecord a " +
"LEFT OUTER JOIN iwrs.location locFrom on locFrom.id=old_value "
I want to map the result to this class:
public class MovementHistoryImpl implements MovementHistory {
private String code;
private String user;
private Date date;
private Location locFrom;
I have no problems getting a List with only scalar properties:
List list = currentSession().createSQLQuery(query)
.addScalar("code")
.setResultTransformer(Transformers.aliasToBean(MovementHistoryImpl.class))
.list();
However, when I want to inject into the locFrom property of MovementHistoryImpl, adding
.addEntity("locFrom",LocationImpl.class)
does not work: the resulting MovementHistoryImpl item has null value for locFrom.
I have inspected without the resultTransformer (ie, returning a List) and I do get a valid (and expected) LocationImpl object. My questions are:
1) How can one populate the MovementHistoryImpl correctly? 2) Does it work if your MovementHistoryImpl property is named differently (initially I h开发者_运维问答ad Location from, instead of locFrom 3) Is it possible to fetch only one property of Location - in reality I'm not interested in locFrom.*, but only locFrom.name, so I wouldn't mind my locFrom object in MovementHistoryImpl to only have the "name" property populated.
精彩评论