我有几个我想要查询的复合主键的sql视图,而且由于Hibernate使用复合键很难,我正在使用createSQLQuery.问题是这个方法只能返回一个List,我需要通过索引来引用colums.
我有可能做一些像jdbc这样的事情并通过他们的sql名称而不是他们的索引来引用列吗?
我需要使用相应的getter和setter迭代和操作列表.我尝试以下基于论坛的答案检索Hibernate查询结果作为结果集而不是列表 但它与下面给出的错误一致.任何人可以建议这里出了什么问题?
Query query = session.createSQLQuery("select s.id,e.firstName, e.middleName from SecurityPrincipals as s " +
"left join Employee as e on e.userId=s.id " +
" where s.id= :userId").addEntity(EmployeeDTO.class);
query.setParameter("userId", userId);
List<EmployeeDTO> list = query.list();
Iterator iterator = list.iterator();
for (int i = 0; i < list.size(); i++)
{
EmployeeDTO employeeDTO = (EmployeeDTO) iterator.next();
System.out.println("FirstName is:"+employeeDTO.getFirstName());
}
Run Code Online (Sandbox Code Playgroud)
以下是我的堆栈跟踪.
Problem accessing /employeelist.jsf. Reason:
org.hibernate.MappingException: Unknown entity: com.fetchinglife.temp.EmployeeDTO
Caused by:
javax.faces.el.EvaluationException: org.hibernate.MappingException: Unknown entity: com.fetchinglife.temp.EmployeeDTO
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIData.broadcast(UIData.java:915) …Run Code Online (Sandbox Code Playgroud) 我需要一个ResultSet来使用openCSV快速导出数据库.我所拥有的是从命名的hibernate查询中检索的List.
如何将此列表转换为结果集,以便保存它?
TY