0
我有一個使用NOT EXISTS
的SQL查詢。如何將此查詢轉換爲HQL?在HQL(休眠)中轉換SQL查詢
這是我的方法:
public List<Cage> getByOwnerId(final Long ownerId, final String agriYearId)
{
return ((List<Cage>)getHibernateTemplate().executeFind(new HibernateCallback(){
public Object doInHibernate(Session session){
String queryString ="select "
+"from tbl_cage c, tbl_actor a, tbl_owner o, tbl_inscasecode i, tbl_country co, tbl_inscasecode g , tbl_code cd"
+" where "
+" i.pk_inscasecodeid = c.FK_CAGETYPE"
+" and cd.PK_CODEID=c.FK_CURRENCY "
+" and co.PK_COUNTRYID = c.fk_country "
+" and G.PK_INSCASECODEID=C.FK_CAGE_INSTALLATIONLOCATION "
+" and c.FK_OWNER = o.PK_OWNERID "
+" and c.FK_OWNER=:ownerId "
+" and "
+ "not exists (select 1 from tbl_policy, tbl_fishpolicy_cage "
+" where c.PK_CAGEID = tbl_fishpolicy_cage.FK_CAGE "
+" and tbl_fishpolicy_cage.FK_FISHPOLICY = tbl_policy.PK_POLICYID AND (tbl_policy.FK_CODEID = '018008' OR tbl_policy.FK_CODEID ='018007' OR tbl_policy.FK_CODEID ='018013' OR tbl_policy.FK_CODEID ='018014') "
+" and tbl_policy.FK_AGRIYEARID=:agriYearId) "
+" and c.PRIMITIVE_COST>0 and c.CAGE_ISDESTROY=0";
Query query = session.createSQLQuery(queryString);
List<Cage> returnList;
query.setParameter("ownerId", ownerId);
query.setParameter("agriYearId",agriYearId);
returnList=query.list();
return returnList;
}}));
}
當我使用List<Object>
,我不能在jsp頁面迭代,當我使用List<Cage>
我得到這個錯誤:can not cast Object to Cage
。