JPA entity
A class marked @Entity whose instances JPA stores as rows in a table, identified by a field marked @Id.
In more detail
An entity represents something with durable identity. Fields map to columns by default, and annotations control names, relationships and nullability. It is shaped for the database, so it need not be the same type a controller returns as JSON.
Example
@Entity public class OrderEntity { @Id private String id; ... }Related terms
- JPA — The Jakarta standard for mapping Java objects to relational database tables and managing them, implemented by libraries such as Hibernate.
- primary key — The column, or columns, whose value uniquely identifies each row of a table and can never be NULL.
- no-argument constructor — A constructor that takes no parameters, which JPA requires on every entity so it can create the object before filling in its fields.
- response model — A type, often a record, that describes exactly the data an API accepts or returns, separate from database entities.
- persistence context — The set of entities JPA is currently tracking in a unit of work, whose changes it writes to the database automatically.
Taught in
- Persistence With JPA And Hibernate — Modern Java: Virtual Threads & High-Throughput Services
- Spring Data Repositories — Modern Java: Virtual Threads & High-Throughput Services
- Database Integration With Testcontainers — Modern Java: Virtual Threads & High-Throughput Services
- Tying It All Together — Modern Java: Virtual Threads & High-Throughput Services