Hibernate gets null for entity instance variables?
I'm trying to implement a feature requires the form to load data for the logged in user.So I wrote a query to get these data for this user ID,Here is a code snippet from the school entity class:
public class ShSchool implements java.io.Serializable {
开发者_JAVA技巧 private long schoolId;
private GsDistrict gsDistrict;
}
I tried to get the data using the following query:
session.createQuery("from ShSchool where schoolId="+schoolId).list();
The problem is that I got values for primitive instance variables and got null for any other data types such as GsDistrict, So what is wrong and how could I got these objects values?
Thanks
Possible causes:
- The gsDistrict is indeed null for that particular user, check the DB to make sure it's not.
- The Hibernate mappings are incorrect.
- The gsDistrict is lazy loaded and you're accessing it outside the Hibernate session. In this case, however, I'd expect an exception to be thrown.
Please include the Hibernate mappings, the problem may be there.
精彩评论