After using hibernate for so long, I have encountered a problem that I have never encountered. Fortunately, I am quick-thinking and good at Lenovo, so that I can discover and solve the problem in a short time. The following is a detailed description.
I added a method in the hibernatedao class as follows:
Public object getbyid (class clazz, string ID) throws hibernateexception {
Return Session. Find ( " From " + Clazz. getname () + " O where O. ID =? " , ID, hibernate. String). Get ( 0 );
}
You know, the primary keys of my PO class are named oid. Coincidentally, some po classes not only have the oId attribute, but also have the property named ID to indicate the business number, such as the instructor number and the education level number. These classes always report the following exceptions when using this method:
Java. Lang. indexoutofboundsexception: Index: 0 , Size: 0
After being depressed for half an hour, I finally thought, will it be the O. ID in the query statement? Does hibernate think that the ID here represents the primary key oid? In debug, we changed the parameter to the oId value, and found that it is true!
Solution: for the moment, I do not know which methods can escape. However, the ID attribute is indeed a bit ambiguous. Change it to code.