I am quoting documentation for this
2.2.1. Mark POJO as a persistent entity
Each persistent POJO class is an entity and is declared using @Entity Annotation (at the class level):
@Entity public class Flight implements Serializable {Long id;
@Id public Long getId() { return id; } public void setId(Long id) { this.id = id; } }
@Entity declares the class as an entity (i.e., a constant POJO class), @Id declares the identifier property of this object. Other Display ads implicitly. The Flight class maps to the Flight Table using the column identifier as the primary key column. Note
The exception configuration concept is central to the JPA specification.
Depending on whether you comment on fields or methods, the type of access used by Hibernate will be a field or property. The EJB3 specification requires that you declare annotations for the type of element that will be accessed, that is, the getter method if you use property access, the field if you use field access. Mixing annotations in both fields and methods should be avoided. Hibernate guesses the type of access from @Id or @EmbeddedId.
There is something called the JPA aka Java Persistence API. Hibernate follows the guidelines for its implementation. So, to make sure it is correctly identified by the JVM (also displayed as an object)
JPA will include any class annotated with @Entity in the save control setting. You do not need persistence.xml if you use annotations. This applies to other JPA implementations as well as Open-JPA.
Usually thumb to Java. J2EE provides recommendations in the form of an interface and annotations in other ways. When someone is developing a J2EE API implementation, they follow these directives. This is a standardization method.
source share