How do you configure Hibernate in a Spring Boot application?
Add spring-boot-starter-data-jpa, set datasource and JPA properties, and define jakarta.persistence entities. Covers ddl-auto, open-in-view, batching and SQL logging.
2,881 posts about Java: questions with answers, tutorials and articles, newest first.
Add spring-boot-starter-data-jpa, set datasource and JPA properties, and define jakarta.persistence entities. Covers ddl-auto, open-in-view, batching and SQL logging.
hibernate-core is the main Hibernate ORM artifact, with the session API, HQL and the JPA implementation. See its coordinates, companion modules and a working example.
Configure Hibernate in a Spring Boot application using Spring Data JPA, with entity mapping, repositories, schema management, N+1 prevention and tests.
@Document marks a class as a MongoDB document and sets its collection. See the default collection name, attributes, repositories and index pitfalls.
Build create, read, update and delete endpoints backed by MongoDB with Spring Data MongoDB, from entity mapping to MongoTemplate partial updates and Testcontainers tests.
Build a Spring Boot REST API backed by MongoDB with Spring Data: configuration, @Document models, repositories, MongoTemplate, and tests.
CascadeType.ALL propagates every JPA entity operation from a parent to its related entities. Use it for composition, not for shared or many-to-many relationships.
CascadeType decides which entity operations propagate from a parent to its children. See each type with a working example and when not to use it.
@OneToOne links two JPA entities one-to-one. See how the owning side, mappedBy, @MapsId, fetch type and cascade settings change the schema and queries.
Use @OneToOne with @JoinColumn on the owning side, mappedBy for the inverse side, and @MapsId when the child shares the parent's primary key.
@ManyToMany maps a many-to-many relationship between two JPA entities using a join table. One side owns it with @JoinTable and the other uses mappedBy.
Map a many-to-many relationship in JPA with @ManyToMany and @JoinTable, keep both sides in sync, and learn when to use a join entity instead.
@OneToMany maps a parent entity to a collection of child entities in JPA. See how mappedBy, cascade, orphanRemoval and fetch strategies work.
Put @OneToMany(mappedBy) on the parent and @ManyToOne on the child, keep both sides in sync, and fetch lazily to avoid N+1 queries.
@Transactional wraps a method in a transaction that commits on success and rolls back on unchecked exceptions. Learn propagation, rollback rules and common pitfalls.
PageRequest is the standard Pageable implementation in Spring Data. It carries page index, page size and sort order, and repositories turn it into a paginated query.
Use @Query with JPQL or native SQL, Specifications for dynamic filters, and custom fragments for complex logic. Examples target Spring Boot 3 and Jakarta Persistence.
@Repository marks a Spring persistence-layer class and translates database exceptions into DataAccessException. Spring Data interfaces do not need it.
A complete Spring Boot 3 CRUD example with JPA: entity, repository, service, controller, validation, pagination and production tips.
@Entity declares a class as a persistent JPA entity mapped to a database table. It needs an @Id and a non-private no-argument constructor.