真的需要使用弹簧数据JPA名为查询吗?
在网络上进行了一些搜索后,我认为使用弹簧数据JPA名称查询时,我们需要一些额外的实现或与Spring Data JPA中派生或动态查询进行比较的定义。在这个场景中,我真的想知道我们真的需要使用弹簧数据JPA名为查询吗?
After making some search on the web, I think that when using Spring Data JPA Named Queries, we need some extra implementation or definitions comparing to the derived or dynamic queries in Spring Data JPA. In this scene, I am really wondering that do we really need to use Spring Data JPA Named Queries?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
春季数据得出的查询仅针对非常简单的查询(有用)。那些查看您自然会提供这种方法的名称的查询,并立即知道如何在SQL或JPQL中实现它。
一旦查询变得更加复杂,我们就不应该再使用派生的查询了,即使我们愿意,也常常无法使用。例如,查询推导无法控制
和
和或之间的优先级。对于所有其他查询,我们需要以一种或其他方式明确编码查询。而且,如果您不希望查询与存储库混合在一起,则指定的查询是一个非常可行的选择。
Spring Data derived queries are intended (and useful) only for very simple queries. Those queries where you look at the name that you would naturally give such a method and would immediately know how to implement it in SQL or JPQL.
As soon as a query gets a little more complex we shouldn't use derived queries anymore, and often we can't even if we wanted to. For example query derivation doesn't have a way to control the precedence between
AND
andOR
.For all other queries we need to explicitly code the query one way or the others. And if you don't want your queries mixed with your repository, a named query is a very viable alternative.