Exception when using HQL query: XXX is not mapped[from xxx where ...]

Source: Internet
Author: User

When using the HQL query in today's project, the Qingaocenterinfo is not mapped[from Qingaocenterinfo where ...] appears.

There is obviously a problem with the hibernate mapping relationship.


This exception occurs first to see whether the table name in the database table is used in the query statement, not the entity class.


To view my code:

Centerlist = Manager.find ("From Qingaocenterinfo center where center.type =?") and Center.centername =? ", new Object[]{type,centername});


Found no problem ah, the solution, from yesterday afternoon to this morning, tinkering for a long time ...

。。。。。


Finally, the problem is found, and the from xxx,xxx used for HQL queries is not the name of the entity class, but the entityname(Hibernate annotation).


Such as:

@Entity @table (name= "Qing_ao_center_info") public class Qingaocenterinfo {         ...}
HereThe specified entityname is not displayed after @Entity, so the name of the entity class is used by default.

In My Code:

@Entity (name= "Qing_ao_center_info") @Table (name= "Qing_ao_center_info") public class Qingaocenterinfo {             ...}

Can be found to indicate theentityname, so when using HQL queries, the FromQing_ao_center_info, not fromQingaocenterinfo;


Centerlist = Manager.find ("From Qing_ao_center_info CENTER where center.type =?") and Center.centername =? ", new Object[]{type,centername});


Related Article

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.