Junior — Middle
Have you worked with JPA when creating database scripts?
sobes.tech AI
Answer from AI
JPA (Java Persistence API) is a specification for working with databases through Object-Relational Mapping (ORM).
When creating database scripts with JPA, SQL is usually not written directly. Instead, entities (Entity) are described as Java classes with annotations. JPA automatically generates the necessary SQL queries for creating, updating, and deleting data.
Example of an entity:
import jakarta.persistence.*;
@Entity
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false)
private String username;
// getters and setters
}
JPA can also automatically create table structures in the database based on the described entities (using hibernate.hbm2ddl.auto settings).
Thus, working with JPA, database scripts are generated and managed automatically, simplifying development and maintenance.