日期:2014-05-20  浏览次数:20751 次

hibernate createSqlQuery 多表查询 没有返回预期对象数组问题
代码如下:
Java code

String sql = "  select wk.a1 ,wk.a2 , {ex.*}  from " +   
             " (select distinct a1,a2 from A ) as wk  join mms_cell {ex} on {ex}.a1= wk.a1 " +   
             " order by wk.a1,wk.a2,{ex}.mydate";   
Query query = getSession().createSQLQuery(sql).   
                          addEntity("ex",User.class);   
List<Object[]> list = query.list();  



期望的是list 中返回的是对象数组格式: 
  a1的值,a2的值,User对象 

但经过对象跟踪 发现list 中只有User对象,a1的值和a2的值丢失, 
who can help me? 


------解决方案--------------------
Java code
Query query = getSession().createSQLQuery(sql).addScalar("a1",Hibernate.STRING).addScalar("a2",Hibernate.STRING).
                          addEntity("ex",User.class);