Database exception collation: Org.hibernate.QueryException:could not resolve property: "Mstation"

Source: Internet
Author: User

Recently, using hibernate as a database query, the results encountered problems:

Org.hibernate.QueryException:could not resolve property: ' Mstation ' of the various steps examined, still did not find the method.

Here, the possible causes of this problem are collated:

First, to troubleshoot the class field in the HQL statement, to see if it is a field in the Java class, not a field in the database;

Second, to check whether each field is consistent with the field in the class, the vast majority of the problem may be due to field mismatch;

Third, if the above two are checked without problems, then it is likely that the JavaBean naming specification is not strictly consistent with the resulting hibernate can not match the field of the problem. (Attached: Naming specification)

JavaBean Class Naming conventions: (Note: To implement a serializable interface (Java.io.Serializable interface))

Specification Reference: http://www.cnblogs.com/Ghost-Draw-Sign/articles/1801476.html

(1) The JavaBean class must be a public class, and its Access property is set to publicly, such as: Common Class user{...}
(2) The JavaBean class must have an empty constructor: there must be a common constructor with no parameters in the class

(3) A JavaBean class should not have public instance variables, class variables are private, such as: private int id;
(4) Attributes should be accessed through a set of access methods (GETXXX and setxxx), typically the IDE (Eclipse, JBuilder) generates Getter/setter methods for properties

The general JavaBean property starts with a lowercase letter, the hump naming format, and the corresponding Getter/setter method is the name of the property that get/set the first letter of capitalization. For example: The property name is username, and its corresponding Getter/setter method is getusername/setusername.

However, there are some special cases:

1 . If the second letter of the property name is capitalized, the property name is used directly as the Get/set in the Getter/setter method, meaning the case is not changed. For example, the property name is Uname, and the method is Getuname/setuname.

2, if the first two letters are uppercase (the general proper nouns and abbreviations will be capitalized), is also the attribute name is directly used as the Getter/setter method in the latter part of the Get/set. For example, the property name is URL, and the method is Geturl/seturl.

3. If the first letter is capitalized, the attribute name is also used directly as the latter part of the Get/set in the Getter/setter method. For example, the property name name, the method is Getname/setname, this is the worst case, will not find the property error, because the default property name is name.

Therefore, you should pay attention to the above naming specification when naming JavaBean.

Database Exception collation: Org.hibernate.QueryException:could not resolve property: "Mstation"

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.