【问题标题】:Can we use JPA Repository to pull/fetch data from Mysql View? If yes How?我们可以使用 JPA Repository 从 Mysql View 中提取/获取数据吗?如果是怎么办?
【发布时间】:2019-04-15 08:43:58
【问题描述】:

我有很多表,我使用 JPARepository 从中获取数据。然后我在 MySql - View 上创建并尝试使用 JPARepository 来做 findAll 但它不起作用。

【问题讨论】:

    标签: mysql spring-data spring-boot-jpa


    【解决方案1】:

    您可以使用本机查询和 DTO 投影:

    public interface ReportRepository extends JpaRepository<SomeEntity, Long> {
    
       @Query(nativeQuery = true, value = "SELECT * FROM yourView")
       List<YourDto> getDateFromYourView();
    
    }
    

    【讨论】:

    • 我会尝试更新。但是根据您的回答,我想到了新的问题,我们可以使用 JPA Criteria on Views 吗?
    猜你喜欢
    • 2021-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多