tags:

views:

1377

answers:

1

I have a VO class which has the getter and setter of another VO class too. For example:

Class DocumentVO{
   PrintJobVO job;
   PrintRunVO run;
   String id;
   getters and setters..
}

Now I have a requirement to use the Native SQL Query using spring hibernate. When I want to map the ids I have a problem. My query is,

select {r.*},{d.*}
from runs {r}, documents {d}
where {r}.RUN_ID as {r.id} = d.RUN_ID as {d.run.id}

Here run is of type PrintRunVO which has its id and other values. How can I map them in my SQL? I am getting an error like invalid user.table.column, table.column, or column specification.

What's the way to overcome this?

A: 

Use the Result Transformer concept in your plain SQL query.

String query = "myquery";
SQLQuery q = session.createSQLQuery(query);
q.addScalar("param1", Hibernate.STRING);
q.addScalar("param2", Hibernate.STRING);
q.setResultTransformer(Transformers.aliasToBean(MyVO.class));
q.setParameter("queryParam1", "some value");
return q.list();
Sandy