Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The solution to the error report of @ Query annotations in SpringDataJpa

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail the solution to the error reporting of @ Query comments on SpringDataJpa. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

SpringDataJpa @ Query comment public interface TimeContentRepository extends JpaRepository {@ Query (value = "select id,user_id as userId,create_time as createTime" + "from time_content where create_time =? 1 and user_id =? 2") List findOnDay (String create_time,String userId);}

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: time_content is not mapped

HQL is written in the comment, so the object is queried, not the table name

Change to

Public interface TimeContentRepository extends JpaRepository {@ Query (value = "select id,user_id as userId,create_time as createTime" + "from TimeContent where create_time =? 1 and user_id =? 2") List findOnDay (String create_time,String userId);}

Caused by: org.hibernate.QueryException: No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode +-[IDENT] IdentNode: 'user_id' {originalText=user_id}

For the same problem, the query field is also a member of the object, not a table field.

The SpringDataJpa @ query annotation uses native code to report an error

The query method of @ query native code has been used before, which can be used with normal annotations, probably in the form of:

Query (value= "select * from table", nativeQuery=true) K_KC54 getK_KC54UsingOriginSQL (String aac001)

As in the above form, the local query problem is solved perfectly.

However, this is queried using @ query native code as usual, and the program reports the following error:

Org.springframework.data.jpa.repository.query.InvalidJpaQueryMethodException: Cannot use native queries...

The problem is found through problem analysis and online search:

@ query native queries cannot be used with pageable for paging queries. To solve this problem, you also want to use the pageable paging feature. The problem can be solved by modifying the native code in the following form:

@ Query (value= "from S_TC70 aac001=?1", countQuery= "select count (1) from S_TC70 aac001=?1") Page getUseOriginS_TC70 (String aac001,Pageable pageable); this is the solution to the @ Query comment on SpringDataJpa. I hope the above can be helpful and learn more. If you think the article is good, you can share it for more people to see.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report