R
Rishtaara
Spring Boot Fundamentals
Lesson 5 of 8Article21 min

Persistence with Spring Data JPA

Persistence with Spring Data JPA

Entity and repository basics

JPA entity and repository
@Entity
public class Course {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;
  private String title;
  private String level;
}

public interface CourseRepository extends JpaRepository<Course, Long> {
  List<Course> findByLevel(String level);
}

JPA tips

  • Prefer DTOs at API boundaries to avoid lazy-loading leaks.
  • Use pagination for list endpoints.
  • Model relationships carefully (`@OneToMany`, `@ManyToOne`).