We compare standard JPA with native Hibernate, focusing on One-to-Many associations and session-based CRUD operations.
10.1. JPA Associations & Native Hibernate APIs
Definition: Bidirectional associations link entities. Native Hibernate APIs provide session-based alternatives to standard JPA interfaces.
Core Working Principles:
- mappedBy: Placed on the parent association. Defines the child entity as the relationship owner that maps to the foreign key column.
- Session vs. EntityManager: Hibernate Session represents the connection context, equivalent to JPA's EntityManager.
// Parent Department
@OneToMany(mappedBy = "department")
List<Employee> employees;
// Child Employee
@ManyToOne
@JoinColumn(name = "dept_id")
Department department;
5-Marks Exam Scoring Points
- mappedBy property defines the child as the relationship owner.
- @JoinColumn creates the foreign key column in the database table.
- Session represents the active database connection context in native Hibernate.