2016-09-21 38 views
2

私はスプリングブートアプリケーションを作成しようとしています。私のアプリケーションでは、デフォルトのsaveメソッドを使用する代わりに、データを保存するカスタムメソッドをいくつか追加したいと考えています。私もImplをしかし、それは動作しませんでしたし、このラインrepositoryImplementationPostfixを変更したSpring Data JPAカスタムメソッドPropertyReferenceExceptionの原因

@Configuration 
@ComponentScan 
@EnableJpaRepositories(repositoryImplementationPostfix = "CustomImpl") 
@Import(RepositoryRestMvcConfiguration.class) 
@EnableAutoConfiguration 
@PropertySource("application.properties") 
public class Application { 

    public static void main(String[] args) { 
     SpringApplication.run(Application.class, args);   
    } 

} 

私のアプリケーションのエントリポイントは次のようなものです。

マイCrudRepository

@RepositoryRestResource 
public interface TaRepository extends CrudRepository<Ta, Integer> ,TestRepository{ 


    List<Ta> findByName(@Param("name") String name); 

} 

マイカスタムリポジトリ:

public interface TestRepository { 
    public void myCustomMethod(TestDto dto); 
} 

マイカスタムリポジトリのImpl

public class TestRepositoryCustomImpl implements TestRepository{ 

    @PersistenceContext 
    private EntityManager em; 
    @Override 
    public void myCustomMethod(TestDto model){ 
} 

NOTE:

私はこれに言及したから私のCrudRepostoryを変更する場合:

@RepositoryRestResource 
    public interface TaRepository extends CrudRepository<Ta, Integer> { 


     List<Ta> findByName(@Param("name") String name); 

    } 

すべてが正常に動作します。しかし、カスタムメソッドの実装ではありません。

+0

これはなんですか?エラーはありますか? – nurgasemetey

+0

原因:org.springframework.data.mapping.PropertyReferenceException:タイプTaのmyCustomMethodプロパティが見つかりませんでした! –

+0

http://stackoverflow.com/questions/20777785/org-springframework-data-mapping-propertyreferenceexception-no-property-catch-f - このリンクでは、 'TestRepositoryCustomImpl'を' TaRepositoryCustomImpl'に、 'TestRepository'を'TaRepositoryCustom' – nurgasemetey

答えて

0

スプリングデータJPA @Repositoryまたは@RepositoryRestResourceでは、カスタムインターフェイスを実装する必要はありません。単純なクエリについては、あらゆる種類のメソッドを作成することができます。簡単なガイドに従ってください。あなたがJpaSpecificationExecutorを使用することができ、複雑なクエリの場合

http://docs.spring.io/spring-data/jpa/docs/1.4.1.RELEASE/reference/html/jpa.repositories.html

How can I create a Predicate from a HQL query?

+0

これは、ルートエンティティの2番目のレベルのフィールド(ex:entity.field.subfield)を他のクエリに遅延させてプリフェッチする必要がある場合をカバーしていません。 –

関連する問題