How do I get data from concatenated tables directly into a class?

Is it possible to get data from a request directly to EmployeeForm

?

Query as a stored procedure empdata p>

SELECT a.name,b.username,b.password FROM Tbemployee left join Tbuser

      

code

   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;

      

This gives me an error:

java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.emp.form.EmployeeForm

      

+3


source to share


1 answer


You need to use ResultTransformer

Another option is to output to List<Object[]>

, which contains rows with columns from the query result, and then iterate and retrieve the data (more work).



A transformer can be something like this:

query.setResultTransformer(Transformers.aliasToBean(EmployeeForm.class));

      

+1


source







All Articles