小编Mic*_*mal的帖子

Spring Data JPA将本机查询结果映射到非实体POJO

我有一个带有本机查询的Spring Data存储库方法

@Query(value = "SELECT g.*, gm.* FROM group g LEFT JOIN group_members gm ON g.group_id = gm.group_id and gm.user_id = :userId WHERE g.group_id = :groupId", nativeQuery = true)
    GroupDetails getGroupDetails(@Param("userId") Integer userId, @Param("groupId") Integer groupId);
Run Code Online (Sandbox Code Playgroud)

我想将结果映射到非实体POJO GroupDetails.

是否有可能,如果可以的话,请你提供一个例子吗?

spring hibernate jpa pojo spring-data

69
推荐指数
4
解决办法
9万
查看次数

Spring data JPA - 使用@EntityGraph 导致“指定的实体图不适用于实体”警告

我将我的应用程序从 spring boot 2.2.5 升级到 2.3.3,并且我正在使用带有 5.4.20.Final 板载的 spring data JPA starter。我的实体在编译时得到增强。

现在,当我在覆盖方法上使用@EntityGraph带有attributePaths属性的注释时,我收到此警告:findAllJpaRepository

2020-08-19 12:13:41.121  WARN 9348 --- [nio-8060-exec-3] [] [] o.h.engine.internal.TwoPhaseLoad         : Entity graph specified is not applicable to the entity [DictionaryLang(id=1601, name=null, lang=null)]. Ignored.
2020-08-19 12:13:41.483  WARN 9348 --- [nio-8060-exec-3] [] [] o.h.engine.internal.TwoPhaseLoad         : Entity graph specified is not applicable to the entity [DictionaryValueLang(id=3051, lang=null, name=null)]. Ignored.
Run Code Online (Sandbox Code Playgroud)

即使此警告 - 图形已正确获取 - 我只能在日志中看到一个 SQL 查询,并且应用程序的行为与更新前一样。

这是我的存储库代码:

public interface DictionaryRepository extends JpaRepository<Dictionary, Long>, QuerydslPredicateExecutor<Dictionary> …
Run Code Online (Sandbox Code Playgroud)

java hibernate spring-data-jpa spring-boot entitygraph

8
推荐指数
1
解决办法
2608
查看次数