When you create an application that uses the JPA, you must follow the requirements for creating the entity classes and the requirements for database mapping determined in the JPA specifications. The requirements for creating entity classes are as follows:
- The entity class must be specified in @Entity or in the entity tag of the O/R mapping file.
- The entity class has a constructor without an argument.
- Do not set enum and interfaces as entity classes.
- The entity or the mapped super-class that form the root of the class hierarchy of the entity class must have a primary key. Make sure that you define one primary key in the entity hierarchy.
- When the entity class instance is passed as a method argument with pass by value, you must implement the Serializable interface.
- The state of the database column is expressed by the instance variable of the entity and the instance variable corresponds to the JavaBean property. Do not change the value of the instance variable by direct access from the client. Change the value through the accessor method (getter/ setter method) or the business method.
- Set the persistent instance variable of the entity to an access level that can be referenced from private, protected, or package.
- Declare the constructor without an argument as public or protected.
- Do not set the entity class to final. Also, do not set the persistence instance variable of the entity class and all the methods to final.
With Cosminexus JPA Provider, if these conditions are not satisfied, an exception might occur. Note that even if an exception does not occur, the operations might not function properly if an entity class that does not satisfy these conditions is created.
Furthermore, for Cosminexus JPA Provider, do not associate one database column with multiple fields in the entity class. If this condition is not satisfied, an exception might occur during the execution of the application. Even if the exception does not occur, the operations might not function properly.