我从 mysql db 获取这个处方列表,我想要做的是,按 Patient_id过滤列表并获取过滤后的列表。
我得到了很好的处方清单。但我无法得到filterList。以下是我的代码。
@Override
@Transactional
public List<Prescription> retrieveAllPrescriptionsByPatientId(int id) {
Session session=sessionFactory.getCurrentSession();
List<Prescription>prescriptions = session.createCriteria(Prescription.class).list() ;
@SuppressWarnings("unchecked")
List<Prescription> filterList =(List<Prescription>) session.createFilter(prescriptions, "where patient_Id = :id").setInteger("id", id).list();
return (List<Prescription>)filterList;
}
这是我得到的例外。
Exception in thread "main" org.hibernate.QueryException: The collection was unreferenced
at org.hibernate.internal.SessionImpl.getFilterQueryPlan(SessionImpl.java:1483)
at org.hibernate.internal.SessionImpl.createFilter(SessionImpl.java:1330)
at com.tela.pms.dao.impl.PrescriptionDAOImpl.retrieveAllPrescriptionsByPatientId(PrescriptionDAOImpl.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at com.sun.proxy.$Proxy19.retrieveAllPrescriptionsByPatientId(Unknown Source)
at com.tela.pms.service.impl.PrescriptionServiceImpl.retrieveAllPrescriptionsByPatientId(PrescriptionServiceImpl.java:47)
at com.tela.pms.Test.HibernateTester.main(HibernateTester.java:45)
这个你能帮我吗。谢谢