16.10.2015 Views

Getting Startedwith pureQuery

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

174<br />

<strong>Getting</strong> Started with <strong>pureQuery</strong><br />

o<br />

• @ColumnOverride<br />

o<br />

provides a single column to property mapping at the bean field level, and is<br />

applied to either the public getter method or the public setter method or the<br />

public field<br />

provides a single override for a column-to-property mapping at the bean<br />

class level that will override a mapping defined using @Column. It will<br />

override the default mapping or any column mapping specified elsewhere<br />

for the bean, even in one of the bean’s superclasses.<br />

• @ColumnOverrides<br />

o<br />

• @GeneratedKey<br />

o<br />

provides a list of column-to-property mappings at the bean class level that<br />

override mappings set using @Column. It will override either the default<br />

mapping, or any mappings specified elsewhere for the bean, even in one<br />

of the bean’s superclasses. @ColumnOverrides makes it easy to define a<br />

bean subclass which needs to map to and from the relational layer<br />

differently than its superclass. This annotation is not used with<br />

@ColumnOverride. They are mutually exclusive.<br />

indicates a property which will be populated by a database generated<br />

value, and is applied to either the public getter method or the public setter<br />

method or the public field. The indicated property is populated prior to<br />

returning from an annotated method in which the bean is used as a<br />

parameter for an SQL insert statement that returns a generated key value.<br />

(The annotation is only supported when the bean is used for non-batched<br />

inserts).<br />

When using annotations to override <strong>pureQuery</strong>’s default mapping mechanism, it is a best<br />

programming practice to be consistent when choosing which bean members to apply the<br />

annotations to, such as always applying @Column annotations to the public getter<br />

methods (this prevents the mistake of accidentally applying two mapping annotations for<br />

the same field, for example, one on the getter and one on the setter).<br />

If you use a <strong>pureQuery</strong> bean to set the SQL parameters of a DML statement, you must use<br />

parameter markers to indicate the name of the bean properties that correspond to the SQL<br />

parameters.<br />

Table 3.1 shows some simple examples using the default <strong>pureQuery</strong> data access layer<br />

mapping between bean fields and SQL results or parameters. For a complete description<br />

of all the options for bean mapping, see the online <strong>pureQuery</strong> documentation:<br />

sql property of<br />

annotated<br />

method<br />

SELECT EMPNO<br />

FROM EMPLOYEE<br />

<strong>pureQuery</strong><br />

bean<br />

Annotation<br />

Bean field or<br />

method<br />

<strong>pureQuery</strong> mapping rule<br />

none setEmpno() Result column name is a case<br />

insensitive match to a field with a<br />

public accessor method

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!