blinkfox / fenix

This is an extension library to the Spring Data JPA complex or dynamic SQL query. 这是一个比 MyBatis 更加强大的 Spring Data JPA 扩展库,为解决复杂动态 JPQL (或 SQL) 而生。https://blinkfox.github.io/fenix
https://blinkfox.github.io/fenix
Apache License 2.0
345 stars 72 forks source link

nativesql查询数据无法直接获取真实实体类型 #16

Closed chenmu5241 closed 4 years ago

chenmu5241 commented 4 years ago

nativesql查询出的list数据只能List《Object》或者List《Map》接收,这个好像是jpa的问题,不知道fenix中是否有办法直接获取到真实的List《Entity》

blinkfox commented 4 years ago

不太懂你的意思,你可以用 List 接收,也可以用 Set 接收,分页的话,就用 Page 去接收,查询出单个数据,就单个对象数据去接收就行。

chenmu5241 commented 4 years ago

多谢你能回复,是这样的,

这是我的repository代码 @QueryFenix(nativeQuery = true) List<Map<String,Object>> queryListByNativeSql(@Param("ids") String[] ids);这个list<Map<String,Object>>本来我是想直接得到实体类的list(List),但是我这样写了之后就会报错,查了相关的问题,好像是jpa的问题,jpa根据nativeSql查询只能映射成List或者List<Map<String,Object>>这是service调用的地方public List queryListByNativeSql(String[] ids) { List<Map<String, Object>> source = projectTotalRepository.queryListByNativeSql(ids); //这里转换成真实对象,如果仅仅为了返回页面大可不必 List list = BeanUtil.convertToEntityList(source, ProjectTotal.class); return list; }

chenmu5241@163.com

发件人: 闪烁之狐 (blinkfox) 发送时间: 2020-05-28 00:14 收件人: blinkfox/fenix 抄送: chenmu5241; Author 主题: Re: [blinkfox/fenix] nativesql查询数据无法直接获取真实实体类型 (#16) 不太懂你的意思,你可以用 List 接收,也可以用 Set 接收,分页的话,就用 Page 去接收,查询出单个数据,就单个对象数据去接收就行。 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

blinkfox commented 4 years ago

@chenmu5241

  1. 如果你查出来的数据,就是单实体表的查询,可以直接返回实体类的集合;
  2. 如果你查出来的数据,是多个表连表查询的结果,且字段是多个表都有的字段,可以用 JPA 投影来返回实体。他的投影功能稍微麻烦点儿,如果不用 JPA 的投影,你可以用 Fenix 提供的返回实体 Bean 的功能,也可以用实体接收。
chenmu5241 commented 4 years ago

太感谢了,resultType这个写法我之前没注意到,真好! 再次感谢!

chenmu5241@163.com

发件人: 闪烁之狐 (blinkfox) 发送时间: 2020-05-28 09:37 收件人: blinkfox/fenix 抄送: chenmu5241; Mention 主题: Re: [blinkfox/fenix] nativesql查询数据无法直接获取真实实体类型 (#16) @chenmu5241 如果你查出来的数据,就是单实体表的查询,可以直接返回实体类的集合; 如果你查出来的数据,是多个表连表查询的结果,且字段是多个表都有的字段,可以用 JPA 投影来返回实体。他的投影功能稍微麻烦点儿,如果不用 JPA 的投影,你可以用 Fenix 提供的返回实体 Bean 的功能,也可以用实体接收。 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

blinkfox commented 4 years ago

@chenmu5241 今天发现了一个诡异的隐藏 bug,在异步多线程中,去调返回自定义实体的查询方法,jpa 不会释放 JDBC 连接,今晚会再发一版,修复这个问题。你到时候可以再更新一下。

chenmu5241 commented 4 years ago

好的,多谢!一定支持!

chenmu5241@163.com

发件人: 闪烁之狐 (blinkfox) 发送时间: 2020-05-28 20:27 收件人: blinkfox/fenix 抄送: chenmu5241; Mention 主题: Re: [blinkfox/fenix] nativesql查询数据无法直接获取真实实体类型 (#16) @chenmu5241 今天发现了一个诡异的隐藏 bug,在异步多线程中,去调返回自定义实体的查询方法,jpa 不会释放 JDBC 连接,今晚会再发一版,修复这个问题。你到时候可以再更新一下。 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

blinkfox commented 4 years ago

@chenmu5241 使用最新的 v2.3.2 版本。

niejianjun commented 4 years ago

支持springboot2.3.1吗?

blinkfox commented 4 years ago

@niejianjun 支持的。

chenmu5241 commented 4 years ago

新版本应该没问题,springboot2.2以上版本,我用的3.0版本对应2.1x

chenmu5241@163.com

发件人: niejianjun 发送时间: 2020-08-14 16:06 收件人: blinkfox/fenix 抄送: chenmu5241; Mention 主题: Re: [blinkfox/fenix] nativesql查询数据无法直接获取真实实体类型 (#16) 支持springboot2.3.1吗? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.