Spring Data JPA 自定义方法导致 PropertyReferenceException [英] Spring Data JPA custom method causing PropertyReferenceException

查看:38
本文介绍了Spring Data JPA 自定义方法导致 PropertyReferenceException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试创建一个 Spring Boot 应用程序.在我的应用程序中,我想添加一些自定义方法来保存数据,而不是使用默认的保存方法.

I have been trying to create a spring boot application. In my application I would like to add some custom methods to save the data instead of using the default save method.

我的应用程序入口点是这样的:

My application entry point is something like this:

@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);         
    }

}

我已将此行repositoryImplementationPostfix更改为Impl,但它不起作用.

I have changed this line repositoryImplementationPostfix to even Impl but, it didn't work.

我的 CrudRepository

My 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);
}

我的自定义存储库实现

public class TestRepositoryCustomImpl implements TestRepository{

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

注意:

如果我将我的 CrudRepostory 从提到的改为:

If I change my CrudRepostory from the mentioned to this:

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


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

    }

一切正常.但不适用于自定义方法实现.

everything works fine. But not with the custom method implementation.

推荐答案

对于 Spring Data JPA @Repository@RepositoryRestResource,您永远不需要实现自定义接口.对于任何简单的查询,您可以创建任何类型的方法,请遵循简单指南.

For Spring Data JPA @Repository or @RepositoryRestResource you never need to implement a Custom Interface. For any simple query you can create any kind of method, please follow the simple guide.

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

对于复杂的查询,您可以使用 JpaSpecificationExecutor.

For a complex query you can use JpaSpecificationExecutor.

如何创建来自 HQL 查询的谓词?

这篇关于Spring Data JPA 自定义方法导致 PropertyReferenceException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆