Junior — Middle
Have you worked with Java Persistence API (JPA) and Hibernate in your projects?
sobes.tech AI
Answer from AI
Yes, I have used the Java Persistence API (JPA) together with Hibernate for database operations through object-relational mapping (ORM). This allows working with database data as regular Java objects without directly dealing with SQL queries.
Example of a simple entity with JPA and Hibernate:
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
@Entity
public class User {
@Id
private Long id;
private String name;
// getters and setters
}
To save an object to the database, EntityManager is used:
entityManager.getTransaction().begin();
entityManager.persist(user);
entityManager.getTransaction().commit();
Hibernate automatically generates SQL queries and manages the state of objects.