I use a ResultTransformer to get an array of DTO objects:
Code:
Session s = sf.openSession();
Query q = s.createSQLQuery("select id, text1, text2, text3, text4 from content where id > 20000");
q.setResultTransformer(new ContentResultTransformer());
Object[] result = null;
for(int i = 0; i < 3; i++) {
long start = System.currentTimeMillis();
result = q.list().toArray();
System.out.println("Duration: " + (System.currentTimeMillis() - start));
}
Code:
public class ContentResultTransformer implements ResultTransformer {
private static final long serialVersionUID = -398323871415254099L;
public Object transformTuple(Object[] arg0, String[] arg1) {
ContentDTO contentDTO = new ContentDTO();
contentDTO.setId(((Integer)arg0[0]).intValue());
contentDTO.setText1((String)arg0[1]);
contentDTO.setText2((String)arg0[2]);
contentDTO.setText3((String)arg0[3]);
contentDTO.setText4((String)arg0[4]);
return contentDTO;
}
public List transformList(List arg0) {
return arg0;
}
}
This query returns 80000 objects, duration with Hibernate is between 3.7 and 4 seconds. When I do the same with iBatis, using the Hibernate connection:
Code:
sqlMap.setUserConnection(s.connection());
long start = System.currentTimeMillis();
List contentDTOs = sqlMap.queryForList("getContent", new Integer(20000));
result = (ContentDTO[]) contentDTOs.toArray(new ContentDTO[contentDTOs.size()]);
System.out.println("Duration: " + (System.currentTimeMillis() - start));
and the SQL-Map
Code:
<sqlMap namespace="Content">
<select id="getContent" resultClass="com.vector.easee.ormappertest.ContentDTO">
SELECT
id,
text1,
text2,
text3,
text4
FROM
content
WHERE
id > #value#
</select>
</sqlMap>
I get the same result in about 1.7 seconds. Do you have any hints why the Hibernate version is that much slower than iBatis ?