Monday, October 16, 2017

10 points about JPA Entity Class for Hibernate Java developers.

JPA Entity class is in core of JPA specification and its one of the most important thing a Java developer should know, while working with JPA implementations like Hibernate. Many Java programmers either not aware of these rules and best practices or doesn't pay enough attention while creating JPA entity class to end up with same mistakes e.g. equals and hashcode not working, issues with access type etc. This motivates me to hund down and write these rules


The entity class must have a no-arg constructor. It may have other constructors as well. The no-arg constructor must be public or protected.
The entity class must a be top-level class. An enum or interface must not not be designated as an entity.
The entity class must not be final. No methods or persistent instance variables of the entity class may be final.
If an entity instance is to be passed by value as a detached object (e.g., through a remote interface), the entity class must implement the Serializable interface.
Both abstract and concrete classes can be entities. Entities may extend non-entity classes as well as entity classes, and non-entity classes may extend entity classes.

http://stackoverflow.com/questions/6033905/create-the-perfect-jpa-entity

Further Learning
Introduction To Hibernate
Spring with JPA and Hibernate
Introduction to Spring MVC
Java Web Fundamentals by Kevin Jones