Hibernates proxy usage for persistent objects

Hibernate's Session.load() returns a proxy instance if proxy usage/lazy loading is not disabled. This proxy instance could be uninitialised.  ie.the fields are not populated. It may throw org.hibernate.LazyInitializationException when the fields of the object is accessed outside a transaction. By default, in Hibernate 3 all classes and collections are lazy initialized. So accessing the objects fields should be done inside a transaction if load() is used and lazy loading is not disabled. Session.get() won't use uninitialized proxies. So it is safe to access objects returned by get() method outside a transaction. To disable usage of proxy, specifiy lazy="false" attribute for class element or default-lazy="false" attribute of hibernate-mapping element. Most scenarios will benefit the usage of proxy and load() should be used.


Popular posts from this blog

java.util.logging - Bad level value for property: org.openqa.level

Downloading source code from SVN/Git repository over HTTP

Suppressing JExcel warnings