1 package de.spring.example.persistence.repository;
3 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
4 import org.springframework.data.jpa.repository.Query;
5 import org.springframework.data.repository.PagingAndSortingRepository;
6 import org.springframework.data.repository.query.Param;
8 import de.spring.example.persistence.domain.Ad;
11 * By default <code>org.springframework.data.jpa.repository.support.SimpleJpaRepository<code>
12 * will be the implementation for this interface.
14 * Be careful with <code>@Transactional</code>. SimpleJpaRepository has annotated methods.
17 public interface AdRepository extends PagingAndSortingRepository<Ad, Long>, JpaSpecificationExecutor<Ad> {
19 // Named Native Query (using the native language of the store) It is not portable.
20 // See de.spring.persistence.example.domain.Ad
21 @Query(value="SELECT * FROM ad WHERE ad.id = :id", nativeQuery=true)
22 Ad findByIdNativeQuery(@Param("id") Long id);
24 // Named Query (using JPL) It is portable.
25 // See de.spring.persistence.example.domain.Ad
26 @Query("select a from Ad a where a.id = :id")
27 Ad findByIdQuery(@Param("id") Long id);