pureQuery recognizes property-level annotations only on public properties and public get() or set() methods. It does not recognize these annotations on private or protected properties.
To understand the conventions that are used in the syntax diagram, see How to read syntax diagrams.
Specifies the SQL column in a database object that a property maps to. You can use this annotation only on public properties and public methods. If you use it anywhere else, pureQuery ignores it.>>-@Column--(--name--=--name_of_column--+-------------------------+->< '-table--=--name_of_table-'
You can use the @Column annotation for either of two reasons:
@Column(name="DEPTNO") public String deptNum;
@Column(name="EMPNO") public String getEmpNum() { return empNum; }
Example
select a.col1, b.col1 from a, b where a.id=b.id;The set() methods for the corresponding properties in the beans that hold the query results need @Column annotations that give the name of the table in which the two id columns appear:
public class JoinExample{ private int a_id; private int b_id; @Column (name="id", table="a") public void setA_id (int a_id) { this.a_id = a_id; } public int getA_id () { return a_id; } @Column (name="id", table="b") public void setB_id (int b_id) { this.b_id = b_id; } public int getB_id () { return b_id; } }
@ColumnOverride(propertyName="extension", column="PHONE") public class EmployeeNewCo extends Employee {...
To understand the conventions that are used in the syntax diagrams, see How to read syntax diagrams.
>>-@ColumnOverride--(--propertyName--=--"--property--",--column--=--"--name--")-><
>>-@ColumnOverrides--(------------------------------------------> .-,----------------------------------------------------------------------------. V | >--{----@ColumnOverride--(--propertyName--=--"--property--",--column--=--"--name--")-+--}--> >--)-----------------------------------------------------------><
Note that the array of @ColumnOverride annotations appears within curly braces within the parentheses for the @ColumnOverrides annotation.
Example
CREATE TABLE HRDEPT.EMPLOYEE( EMPNO CHAR(6) NOT NULL, FIRSTNME VARCHAR(12) NOT NULL, MIDINIT CHAR(1), LASTNAME VARCHAR(15), WORKDEPT CHAR(2), PHONENO CHAR(4), HIREDATE DATE, PRIMARY KEY(EMPNO))Some of the column names are abbreviated or do not follow Java naming conventions.
The following definition for an Employee bean uses @Column annotations to provide more meaningful names to the users of objects of the com.company.Employee class.
public class Employee { private String employeeId; private String firstName; private String middleInitial; private String lastName; private String departmentId; private String extension; private Date hireDate; @Column(name = "EMPNO") public String getEmployeeId () { return employeeId; } public void setEmployeeId (String employeeId) { this.employeeId = employeeId; } @Column(name = "FIRSTNME") public String getFirstName () { return firstName; } public void setFirstName (String firstName) { this.firstName = firstName; } @Column(name = "MIDINIT") public String getMiddleInitial () { return middleInitial; } public void setMiddleInitial (String middleInitial) { this.middleInitial = middleInitial; } public String getLastName () { return lastName; } public void setLastName (String lastName) { this.lastName = lastName; } @Column(name = "WORKDEPT") public String getDepartmentId () { return departmentId; } public void setDepartmentId (String departmentId) { this.departmentId = departmentId; } @Column(name = "PHONENO") public String getExtension () { return extension; } public void setExtension (String extension) { this.extension = extension; } public Date getHireDate () { return hireDate; } public void setHireDate (Date hireDate) { this.hireDate = hireDate; } }
Now, suppose an application runs against a database with a slightly different schema. The table is defined as follows:
CREATE TABLE HRDEPTNEWCO.EMPLOYEE( EMPNO CHAR(6) NOT NULL, FIRSTNME VARCHAR(12) NOT NULL, MIDINIT CHAR(1), LASTNAME VARCHAR(15), WORKDEPT CHAR(2), PHONE CHAR(4), HIREDATE DATE, PRIMARY KEY(EMPNO))
You can subclass the Employee bean to override the previous annotation so that you can work with the new table definition. The beginning of the subclass might look like this:
@ColumnOverride(propertyName="extension", column="PHONE") public class EmployeeNewCo extends Employee {...