我正在使用休眠模式。我有一个清单。我在dao层上使用了hql。但是我的名单不存在。但是我打开了show_sql = true。然后,本地sql正在工作。为什么我的本机sql可以运行,但是hql却不起作用。
休眠查询
customers = entityManager.createQuery(
"SELECT c FROM LoungeCustomerCash c where c.operationDate between :beginDate and :endDate and c.boardingPass.operatingCarrierDesignator= :iataCode ORDER BY c.operationDate DESC")
.setParameter("iataCode", iataCode).setParameter("beginDate", beginDate)
.setParameter("endDate", endDate).getResultList();
本地sql查询:
select loungecust0_.id as id2_59_, loungecust0_.CREATEDATE as CREATEDATE3_59_, loungecust0_.CREATEUSER as CREATEUSER4_59_, loungecust0_.UPDATEDATE as UPDATEDATE5_59_, loungecust0_.UPDATEUSER as UPDATEUSER6_59_, loungecust0_.VERSION as VERSION7_59_, loungecust0_.BOARDINGPASSID as BOARDINGPASSID14_59_, loungecust0_.customerType as customerType8_59_, loungecust0_.fullName as fullName9_59_, loungecust0_.LOUNGESERVICEID as LOUNGESERVICEID15_59_, loungecust0_.operationDate as operationDate10_59_, loungecust0_.price as price11_59_, loungecust0_.bankName as bankName12_59_ from LNCUSTOMER loungecust0_ cross join LNBOARDINGPASS boardingpa1_ where loungecust0_.service_type='CASH' and loungecust0_.BOARDINGPASSID=boardingpa1_.id and (loungecust0_.operationDate between to_timestamp('23/09/2018 11:09:02,660000000','DD/MM/RRRR HH24:MI:SSXFF') and to_timestamp('23/12/2018 11:09:02,660000000','DD/MM/RRRR HH24:MI:SSXFF') ) and boardingpa1_.operatingCarrierDesignator='LH' order by loungecust0_.operationDate DESC
答案 0 :(得分:0)
尝试使用重载的createQuery方法,该方法接受结果类作为第二个参数:
List<Customer> customers = entityManager.createQuery("...query ...", Customer.class)
// set parameters
.getResultList();