6.12.4 Creating the accessor method

This subsection describes the signature rules of the accessor method and the addition of the business logic to the accessor method.

Organization of this subsection
(1) Method signature rules of the accessor method
(2) Adding the business logic to the accessor method

(1) Method signature rules of the accessor method

When Cosminexus JPA Provider accesses a persistence property, the accessor method of the property must follow the same method signature rules as the following JavaBeans:

For a property that returns the return value boolean, you can also change the name of the getter method to isProperty. Note that when you use Cosminexus JPA Provider, an exception occurs when the application starts if only the getter method or the setter method exists.

Also, when you handle collection values in the persistence fields and persistence properties, define the following collection values in the interface:

If the persistence property becomes a collection value, set the accessor method signature to one of these interfaces or you can also use the generic type of these collections (example: Set<T>).

(2) Adding the business logic to the accessor method

In addition to the setter/ getter processing of the property, the accessor method can also include the business logic, such as verifying the values. If the access type is property, the business logic operates when Cosminexus JPA Provider invokes the accessor method.

In this case, however, note the following points:

If the Runtime exception occurs in the property accessor method, the current transaction is marked for rollback. If Cosminexus JPA Provider reads the persistent contents of the entity and throws an exception in the accessor method used for storing the contents, the transaction is rolled back. Also, the PersistenceException exception that wraps the application exception occurs.