How do you implement cascade operations in JPA?
Learn JPA cascade types, orphanRemoval and a working Order and OrderItem example, plus which relationships should cascade and which should not.
2,887 posts about Java: questions with answers, tutorials and articles, newest first.
Learn JPA cascade types, orphanRemoval and a working Order and OrderItem example, plus which relationships should cascade and which should not.
@ManyToOne maps many child entities to one parent via a foreign key. See fetch types, @JoinColumn, bidirectional mapping and N+1 pitfalls.
@JoinColumn maps the foreign key column of a JPA association. See many-to-one, one-to-many, one-to-one, composite keys and when to use @JoinTable instead.
How @ManyToMany and @JoinTable map a many-to-many relationship in JPA, with unidirectional and bidirectional examples, cascade rules and fetching advice.
Map a JPA one-to-many relationship the right way: bidirectional @OneToMany and @ManyToOne, cascade, orphanRemoval and lazy fetching with examples.
Map one-to-one relationships in JPA using a foreign key, mappedBy or a shared primary key with @MapsId, and avoid common lazy loading pitfalls.
@GeneratedValue lets JPA generate primary keys. Compare the AUTO, IDENTITY, SEQUENCE, TABLE and UUID strategies and learn which one fits your database.
Learn how to define simple, generated and composite primary keys in a JPA entity, and how to choose between IDENTITY, SEQUENCE and UUID.
@Table maps a JPA entity to a specific table and sets its schema, unique constraints and indexes. Examples use Jakarta Persistence and Hibernate.
JPA is a specification and Hibernate is an implementation of it. See how they relate, how Spring Data JPA fits in and when to use Hibernate-only features.
Learn how FetchType.LAZY works in JPA and Hibernate, why LazyInitializationException happens and how to fetch data with entity graphs, JOIN FETCH and DTOs.
The JPA EntityManager manages the persistence context and entity lifecycle. This guide covers CRUD, dirty checking, queries and thread safety.
Learn JPA CRUD with EntityManager and Spring Data JpaRepository: persist, find, update through dirty checking, delete, pagination and transaction handling.
JPA repositories are interfaces that Spring Data JPA implements for you, giving CRUD, query methods and paging with no boilerplate.
@Entity makes a Java class a managed JPA entity mapped to a table. Learn the requirements, lifecycle states and the difference from @Table.
Learn how to define an entity class in JPA with @Entity and @Id, customize columns, generate keys and map relationships on Jakarta Persistence.
JPA is the Java specification for mapping objects to relational tables. See entities, the EntityManager, JPQL, the jakarta.persistence rename and common performance fixes.
Learn to control JDBC transactions with auto-commit, commit and rollback, savepoints, isolation levels and batching, with safe try-with-resources code.
Connection pooling reuses open database connections instead of creating one per request. See how it works and how to set up HikariCP in Java and Spring Boot.
PreparedStatement binds values to placeholders and blocks SQL injection, while Statement runs concatenated SQL. See examples, a comparison table and batching.