Entity Related Annotations
- Entity: This annotation of the java class can indicate that it is the entity and it can represent the tables in the relational database. Example: @Entity
- Table: This annotation that can specifies the details of the database table to which the entity is mapped. Example: @Table
- Id: This annotation can mark the field in the entity as the primary key. Example: @Id
- GeneratedValue: This annotation can be configured the way primary key values are generated for the entity. Example: @GeneratedValue(strategy = GenerationType.IDENTITY)
- Column: This annotation can be specifies the maps of an entity field to the database column. Example: @Column
- Basic Configure: This annotation can specify the default fetch type for an entity field. Example: @Basic(fetch = FetchType.LAZY)
- Transient: This annotation can mark the field in the entity as the transient and it will not be persisted in the database. Example: @Transient
- ManyToOne: This annotation can define the many-to-one relationship between the entities. Example: @ManyToOne
- OneToMany: This annotation can define the one-to-many relationship between the entities. Example: @OneToMany
- OneToOne: This annotation can define the one-to-one relationship between the entities.
- JoinColumn: It can defined as the specifies the mapping of the foreign key column in the relationship. Example: @JoinColumn
- JoinTable: This annotation can be specifies the mapping of the intermediate table in the many to many relationship. Example: @JoinTable
- Getter and Setter Methods: This methods can be used to retrieve and set the values of the entity fields.
JPA – Creating an Entity
JPA is defined as Java Persistence API (JPA) that can simplify the process of the persisting Java objects to the relational databases. Creating the entity in the JPA involves defining the java class that can represent the database table and it can be annotated with the JPA annotations to specify its mapping to the database schema.
Contact Us