9.12.4 Creating the accessor method
This section 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
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:
-
T getProperty()
-
void setProperty(T t)
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:
-
java.util.Collection
-
java.util.Set
-
java.util.List
-
java.util.Map
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:
-
The order in which the accessor methods that load and store the persistent states are invoked, is not defined when Cosminexus JPA Provider is executed. Therefore, the execution order of the logic included in getter is not yet decided.
-
For portability when the access type is property and lazy fetch is specified in the persistence property, we recommend that you do not access the entity contents until the entity contents are fetched by Cosminexus JPA Provider.
-
When the access type is property and when a logic that changes the value is added as the business logic, Cosminexus JPA Provider does not guarantee data consistency.
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.