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.

Comments

Popular posts from this blog

Multi Tenant applications using PostgreSQL Row Level Security

Recovering Dell Laptop Windows OS using factory image from Linux bootable USB drive

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