Accessing an object's fields without an active session

后端 未结 1 1153
深忆病人
深忆病人 2021-01-27 15:47

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

相关标签:
1条回答
  • 2021-01-27 16:24

    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.

    0 讨论(0)
提交回复
热议问题