I'm trying to figure out a better way to write this query in my
mapping file so that I get my object returned correclty. Bare with me
because there is a bit of code to look at. First here is the object I
am trying to fill. I will only show the fields, just know that they
each have getters and setters:
public class Issue implements Serializable
{
private int issueId;
private String issueNumber;
private Date dateCreated;
private Date dateAccepted;
private Date dateResolved;
private Date dateModified;
private Date dateExpResolve;
private User createdByUser;
private Employee employee;
private String workstationName;
private Workstation workstation;
private Monitor monitor;
private Hardware hardware;
private Printer printer;
private PrinterProblem printerProblem;
private System system;
private IssueType issueType;
private IssueAction issueAction;
private IssueLevel issueLevel;
private IssueStatus issueStatus;
private String summary;
private String additionalInformation;
private User acceptedByUserId;
private User reopenedByUserId;
private User resolvedByUserId;
....
}
The statement I have so far, and it works, but I need to add to it but
I am afraid that just supplying all the AND's in the WHERE clause is
not very good design. I should probably be using some sort of join.
Here is the statement in my issue.xml file.
<statement id="getAllIssuesForEmployee" parameterClass="int"
resultMap="get-issue-result">
select * from
t_issue, t_user, t_employee, t_issue_status
WHERE
creating_user_id = user_id
AND
t_issue.status_id = t_issue_status.status_id
AND
t_employee.employee_id = t_issue.employee_id
AND
t_issue.employee_id = #value#
</statement>
Here is my resultMap
<resultMap id="get-issue-result"
class="com.gthought.anykey.web.modelbeans.Issue">
<result property="issueId" column="issue_id"/>
<result property="dateCreated" column="date_created"
javaType="java.util.Date"/>
<result property="dateAccepted" column="date_accepted"
javaType="java.util.Date"/>
<result property="dateResolved" column="date_resolved"
javaType="java.util.Date"/>
<result property="dateModified" column="date_modified"
javaType="java.util.Date"/>
<result property="dateExpResolve" column="date_exp_resolve"
javaType="java.util.Date"/>
<result property="createdByUser" column="creating_user_id"
select="User.getUserById"/>
<result property="employee" column="employee_id"
select="Employee.getEmployeeById"/>
<result property="workstationName" column="workstation_name" />
<result property="workstation" column="workstation_id"
select="Workstation.getWorkstationById"/>
<result property="acceptedByUserId"
column="accepted_by_user_id" select="User.getUserById"/>
<result property="issueNumber" column="issue_number"/>
</resultMap>
Any hints and/or tips are appreciated.
Thanks.
Gregg Bolinger