Junior — Middle
Can you explain what ORM is in the context of JPA and how it works?
sobes.tech AI
Answer from AI
ORM (Object-Relational Mapping) is a technology that allows working with a database through programming language objects, hiding the details of SQL queries and data transformation.
In the context of JPA (Java Persistence API), ORM is implemented through mapping Java classes to database tables. JPA manages the lifecycle of objects, their states (new, managed, detached, removed), and automatically synchronizes changes with the database.
Example:
@Entity
public class User {
@Id
@GeneratedValue
private Long id;
private String name;
// getters and setters
}
Here, the User class corresponds to a table, and the fields correspond to columns. JPA allows saving, updating, and retrieving User objects without writing SQL.