Hi Yusuf,
This is a big question!
Clinton is right that a JavaBean will be faster, but I've always thought that the performance gain will be negligible and not noticed by any user. For me, this is not enough of an argument one way or the other.
I have been on both sides of the issue with Maps. I like maps because I don't have to create a POJO for every query. But also like the more robust datatype mapping that is available if you make a POJO. And you can use iBATIS "group by" functionality with a POJO and fill out a big object graph if you need to.
For me the bottom line is that you should create a good POJO based domain model for your application, and then map as many of those classes to iBATIS methods as possible. If you need to add an occaisional Map here and there for a wierd one-of-a-kind query, then I'd do it rather than messing up the domain model.
So the domain model is most imprtant to me.
My thoughts...
Jeff Butler
On 1/19/06, Yusuf <[EMAIL PROTECTED]> wrote:
Hello,
I've been using ibatis for quite some time now, and I like to ask some
questions to all ibatis gurus out there...
- For queries with joins from many table, i usually map results to a Map
(no need to make custom beans), for example:
<select id="employeeData" resultClass="map">
SELECT *
FROM dept, emp, bonus
WHERE dept.deptno = emp.deptno AND emp.ename = bonus.ename(+)
</select>
But in the wiki about improving sqlmaps performance
( http://opensource2.atlassian.com/confluence/oss/display/IBATIS/How+do+I
+improve+SQL+Map+performance),
Mr. Clinton said that always use a java bean to improve performance,
maybe like this:
<select id="employeeData" resultMap="employeeResultMap">
SELECT *
FROM dept, emp, bonus
WHERE dept.deptno = emp.deptno AND emp.ename = bonus.ename(+)
</select>
<resultMap id="employeeResultMap" class="com.test.EmployeeData ">
...
</resultMap>
But how if we have so many multiple table queries, should I just make a
bean class for each custom queries i made (there are many of them)? Or
should I make a bean for each table in the database, for example maybe
we have classes Employee, Dept, Bonus, and define the resultMap like
this:
<resultMap id="employeeResultMap" class="com.test.ResultClass">
<result property="dept.deptno " column="DEPTNO" javaType="string"
jdbcType="VARCHAR2"/>
...
<result property="emp.empno" column="EMPNO" javaType="string"
jdbcType="VARCHAR2"/>
...
<result property="bonus.comm" column="COMM" javaType="string"
jdbcType="VARCHAR2"/>
...
</resultMap>
and the ResultClass:
class ResultClass{
private Dept dept;
private Emp emp;
private Bonus bonus;
//... getter setter
}
Thank you, and I'm sorry for a rather long question, but I've been
wondering about how do people used to map their results.
Yusuf
