I\'m using Hibernate 4.0.1.Final. Is it possible to access an object\'s fields if that object has been loaded via the org.hibernate.Session.load(Class clazz, Serializable id) m
Use session.get(Class, Serializable)
instead of session.load(Class, Serializable)
Load will return a proxy to the object, this object is loaded from the database when you first access a property on the proxy. If you use session.get()
you're guaranteed to get a fully initialized object back.
The other difference between load and get is the result of an object not being found. Get will return null whereas load will always return a proxy. This proxy will throw an exception when a property is accessed.