Hibernate:
select
(select
ms.nickname
from
Memberstatus as ms
where
ms.MemberId=t.FPMemberId) as fpname,
(select
ms.nickname
from
Memberstatus as ms
where
ms.MemberId=t.SPMemberId) as spname,
(case t.Status
when '1' then '正在换车'
when '2' then '换车完成'
end) as st,
t.StartTime,
t.`FPMemberId` as fpid,
t.`SPMemberId` as spid
from
`Transfer` as t
where
t.Status in (
'1','2'
)
and t.EndTime<=sysdate()
order by
t.StartTime limit 0,
7
2013-59-03 10:59:26could not read column value from result set: FPMemberId; Column 'FPMemberId' not found.
2013-59-03 10:59:26SQL Error: 0, SQLState: S0022
2013-59-03 10:59:26Column 'FPMemberId' not found.
将以上sql粘贴到mysql工具中执行完全没有任何问题,这就怪了。
最后折腾处理如下:
select * from (原来的查询sql) as 别名
最后行了!
完整如下:
/**
* 获得换车动态
* @return
*/
public List getTransDynamic(){
Object result = super.commonDao.execute(new IHibernateCallback() {
public Object doInHibernate(Session session) {
String sql ="select * from (" +
"select "+
"(select ms.nickname from Memberstatus as ms where ms.MemberId=t.FPMemberId) as fpname, "+
"(select ms.nickname from Memberstatus as ms where ms.MemberId=t.SPMemberId) as spname, "+
"(case t.Status "+
" when '1' then '正在换车' "+
" when '2' then '换车完成' "+
"end) as st, "+
"t.StartTime, "+
"t.`FPMemberId` as fpid, "+
"t.`SPMemberId` as spid "+
"from `Transfer` as t "+
"where t.Status in ('1','2') and t.EndTime<=sysdate() "+
"order by t.StartTime "+
"limit 0,7 "+
") as model";
return session.createSQLQuery(sql).list();
}
});
return result==null?null:(List)result;
}