The following code is Spring Data JPA JPQL sample:
public interface ServerRepository extends JpaRepository<Server, Long> {
@Query("SELECT application FROM Application application WHERE application.server = :server")
List<Application> getAllApplications(@Param("server") Server server);
}
and the following code tests it:
@Autowired
ServerRepository serverRepository;
@Test
public void testGetAllApplications() {
Server server = serverRepository.findOne(1L);
serverRepository.getAllApplications(server).stream().forEach(System.out::println);
}
Reference:
http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.named-parameters
No comments:
Post a Comment