7. Other Methods
Custom Implementation
EntityManager
- Criteria API
public class CustomUserRepositoryImpl implements CustomUserRepository {
@PersistenceContext
private EntityManager entityManager;
@Override
public List<User> findUsersCustomMethod(String criteria) {
String query = "SELECT u FROM User u WHERE u.criteria = :criteria";
return entityManager.createQuery(query, User.class)
.setParameter("criteria", criteria)
.getResultList();
}
}
public interface UserRepository extends JpaRepository<User, Long>, CustomUserRepository {
// 기본 JPA 쿼리 메서드
}
JdbcTemplate (native SQL)
Stored Procedure (DB)
@StoredProcedure
public interface UserRepository extends JpaRepository<User, Long> {
@Procedure(name = "FIND_USERS_BY_STATUS")
List<User> findUsersByStatus(@Param("status") String status);
}
'Spring > Spring Data JPA' 카테고리의 다른 글
[Spring Data JPA] 3-2. JPA Query Methods (4) (0) | 2024.08.02 |
---|---|
[Spring Data JPA] 3-2. JPA Query Methods (6) (0) | 2024.08.02 |
[Spring Data JPA] 3-2. JPA Query Methods (5) (0) | 2024.08.02 |
[Spring Data JPA] 3-2. JPA Query Methods (2) (0) | 2024.08.02 |
[Spring Data JPA] 3-2. JPA Query Methods (1) (0) | 2024.08.02 |