Ive found that if you want to stick with standard sql and use hibernate at the sametime, use createSQL()
Iterator results = sqlSession.createSQLQuery(query)
You are also going to want to use .addScalar after that too. This will indicate which values you are actually returning.
String query = "select a, b from table";
Iterator results = sqlSession.createSQLQuery(query)
.addScalar("a",Hibernate.STRING)
.addScalar("b",Hibernate.STRING).list().iterator();
then you can pull the values out by going through the iterator like this
while (results.hasNext()) {
Object[] column = (Object[]) results.next();
the value for a will be in column[0] and the value for b will be in column[1]
hope that helps.
|