【问题标题】:Join using two different entities in spring data jpa在spring data jpa中使用两个不同的实体加入
【发布时间】:2019-04-18 13:21:09
【问题描述】:

我有 2 个不同的实体。 table1 有一列是 table2 的主键。

这两个表都尊重存储库。

如果我在其中一个存储库中编写以下查询,则会出现错误

QuerySyntaxException:意外令牌:

@Query("select new stats.UserCountDTO(b.objectiveId, count(b.objectiveId), a.locationCountry)"+ 
" from UserIdentityEntity a, UserObjectiveEntity b where b.userIdentityId == a.id and b.cId = ?1")

在这种情况下如何使用 spring data jpa 编写连接查询?

【问题讨论】:

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


【解决方案1】:

你只是犯了一个错误。

b.userIdentityId == a.id 

应该是:

b.userIdentityId = a.id

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-27
    • 2016-10-10
    • 1970-01-01
    • 2019-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多