【发布时间】:2017-07-26 11:13:22
【问题描述】:
是否可以将查询中的数据直接检索到EmployeeForm?
查询为存储过程empdata
SELECT a.name,b.username,b.password FROM Tbemployee left join Tbuser
代码
List<EmployeeForm> form = new ArrayList<EmployeeForm>();
EmpDB service = (EmpDB) RuntimeAccess.getInstance().getServiceBean(
service.begin();
Session session = service.getDataServiceManager().getSession();
SQLQuery query = session.createSQLQuery("EXEC empdata");
List list = query.list();
formList = list;
这给了我一个错误:
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.emp.form.EmployeeForm
【问题讨论】:
-
使用JPA 进行对象/关系映射。
-
你是说我可以制作不是数据库表的实体吗?
-
是的,使用
ResultTransformer。 -
谢谢先生 resulttransformer 就是我要找的