When more than one column or expression appears in a SELECT statement's select-list, while in some situations there will be no natural transformation of the columns selected to any existing Bean class, there often will be a natural transformation. In many applications a SELECT statement's select-list accesses exactly the data needed to populate (in whole, or in part) an instance of an existing Bean class.
The following SELECT statement's select-list, for example, supplies data needed to fully populate an instance of the bean class com.company.Employee.
SELECT EMPNO, FIRSTNME, MIDINIT, LASTNAME, WORKDEPT, PHONENO, HIREDATE FROM HRDept.Employee
The bean uses the following definition:
public Employee { @Column(name="EMPNO") public String employeeId; @Column(name="FIRSTNME") public String firstName; @Column(name="MIDINIT") public String middleInitial; public String lastName; @Column(name="WORKDEPT") public String departmentId; @Column(name="PHONENO") public String extension; public Date hireDate; }
The target class's @Column annotations provide information needed to associate columns of the select-list with their respective properties; no @Column annotation is specified for either lastName or hireDate, because those properties match their respective column label names in the table HRDept.Employee.