SPRINGDATA:XXX_XXX is not mapped

Source: Internet
Author: User

Write a query today, the error is as follows

' Tag_articlerepository 'publicabstract java.util.List com.fdzang.mblog.repository.Tag_ Articlerepository.getbytag_oid (java.lang.String)!   for type tag_article!

Query repository as follows

 Package com.fdzang.mblog.repository; Import com.fdzang.mblog.pojo.Tag_Article; Import org.springframework.data.jpa.repository.JpaRepository; Import java.util.List;  Public Interface extends Jparepository<tag_article,string> {    List<Tag_Article> getbytag_oid (String tag_ OID);}

The first thought was that there was definitely a problem with the underscore, because JPA was strict with naming conventions and was tested with @query annotations

tag_article ta WHERE ta.tag_oid =: tag_oid ")    List<Tag_Article> getbytag_oid (@Param (" Tag_ OId ") String tag_oid);

The error is as follows

tag_article is not mapped

Then after a setback, finally found out where the mistake

tag_article ta WHERE ta.tag_oid =: tag_oid ")    List<Tag_Article> getbytag_oid (@Param (" Tag_ OId ") String tag_oid);

In the @query annotation, it should be the name of the entity, not the table name of the database, case-sensitive

This should be the underlying reason for hibernate, which is caused by the fact that he is unfamiliar with hibernate.

Finally, summarize:

The above is still Silicon Valley tong just teacher Springdata tutorial, roughly meaning in the springdate simple query, underline has a specific meaning

His parsing will take precedence over the comparison of attributes in the class.

This time, getbytag_oid () will parse to Tag_Article.Tag.oId instead of tag_article.tag_oid .

Because the underscore has a higher precedence, the underscore is parsed first and then compared in the class

When encountering this kind of problem we can develop based on annotations, after all, Springdata simple query is simple, but because of the rigid, so the naming aspect is very harsh

Of course, the best thing is not to use the damn underline! Ha ha

SPRINGDATA:XXX_XXX is not mapped

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.