Code Explainers

Code explainers tagged #jpa

java
@Entity
@Table(name = "orders")
@SQLDelete(sql = "UPDATE orders SET deleted = true, deleted_at = now() WHERE id = ?")
@Where(clause = "deleted = false")

Soft deletes with Hibernate in Spring

soft-delete jpa hibernate
Intermediate 9 steps
java
@Repository
public interface OrderRepository extends JpaRepository<Order, Long> {
 
    @Query("""

Keyset pagination with Spring Data JPA

pagination cursor jpa
Advanced 8 steps
java
@Repository
public interface OrderRepository extends JpaRepository<Order, Long> {
 
    @EntityGraph(attributePaths = {"customer", "lineItems", "lineItems.product"})

Killing N+1 queries with @EntityGraph in Spring

orm fetching n+1-problem
Intermediate 5 steps
java
@DataJpaTest
@Testcontainers
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
class OrderRepositoryIT {

Testing a JPA repository against real Postgres in Spring

integration-testing testcontainers jpa
Intermediate 8 steps
java
@Entity
@Table(name = "accounts")
public class Account {
 

Optimistic locking with @Version in Spring

optimistic-locking jpa concurrency
Advanced 7 steps
java
@Repository
public interface OrderRepository extends JpaRepository<Order, Long> {
 
    @QueryHints(@QueryHint(name = HINT_FETCH_SIZE, value = "1000"))

Streaming large result sets in Spring Data JPA

streaming jpa memory-management
Advanced 6 steps