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"