简体   繁体   中英

Spring Hibernate SQL Query

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?

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM