Spring Data JPA
Spring Data JPA에서는 JpaRepository 인터페이스를 구현하는 클래스 자동생성
Jpa레포지토리 인터페이스를 상속받은 인터페이스가 자동으로 스캔이 되면
해당 인터페이스 정보를 토대로 자동으로 SimpleJpaRepository 클래스를 생성해주고 Bean에 등록!
사용법
JpaRepository<"@Entity 클래스", "@Id 의 데이터 타입">를 상속받는 interface 로 선언합니다.
JPA Auditing
@MappedSuperclass 애너테이션 (엔티티 클래스의 상속)
이것이 선언된 클래스를 상속받는 클래스는 해당 선언된 클래스의 필드를 컬럼으로
갖는 엔티티가 됨
Query Methods
-사용자가 메서드 이름을 정해진 규칙에 따라 조합해 만들어서 선언만 하면 SimpleJpaRepository에서 분석해 알아서 해당기능메서드를 만들어 주는 매우 편리한 기능
public interface MemoRepository extends JpaRepository<Memo, Long> {
List<Memo> findAllByOrderByModifiedAtDesc();
}
// findAllByOrderByModifiedAtDesc() 메서드는 존재하는 메서드가 아님!