In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the JPA @ query can not use limit function to solve the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that you can not use limit function to solve the article after reading this JPA @ Query will have something to gain, let's take a look at it.
Cannot use limit function when JPA @ query
When using ssh, I added springdata-jpa to query sql.
When using the limit function in @ query, an error is reported. Later, after analyzing the reason, we know that the sql called JPQL,jpql written in @ query of springdata-jpa does not support the limit function.
Native sql supports the limit function, so how do we write native sql in query?
Solution @ Query (nativeQuery=true,value = "")
Write normal sql statements in value
If the entity object corresponding to the database is returned, then the alias of the returned result set field of sql should be the same as the corresponding database field name in the entity class. There can be extra fields, but no fewer fields.
Public interface GaidDao extends LogicDeleteableRepository, JpaSpecificationExecutor {/ / add: when nativeQuery annotation, write native sql, support limit function / / do not join: nativeQuery annotation is JPQL. JPQL does not support the limit function @ Query (nativeQuery=true, value = "select gaid from sdp_gaid where geo =? 1 and deleted = 0 order by id desc limit 1000000") List findGaidByGeo (String geo);}
The use of limit function in JPA @ Query annotation does not support limit function
All want to use native sql statements
@ Query (value = "select * from d_quarterly_report where report_type=?1 order by cycle_number desc limit 1", nativeQuery = true) QuarterlyReport getLastUploadByReportType (Boolean type)
Instead of
@ Query (value = "select * from d_quarterly_report where report_type=?1 order by cycle_number desc limit 0Power1", nativeQuery = true,) QuarterlyReport getLastUploadByReportType (Boolean type)
The only way to write limit 0jue 1 that is not supported in jpa is limit 1.
This is the end of the article on "how to solve the problem of not using the limit function when JPA @ Query". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to use limit function when JPA @ query". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.