views:

61

answers:

1

load() just returns a proxy by default and database won’t be hit until the proxy is first invoked.

what does it mean by proxy exactly here ?

+1  A: 

First of all, Proxy is a design pattern. In sense of Hibernate, it is dynamically subclassing your object at runtime. The proxy object will contain the same methods as your object(that's why you don't realize that you are dealing with a proxy), and as you say the database won’t be hit until the proxy is first invoked.

Petar Minchev
what i understood from ur answer is "ahen load is invoked it will first check the persistance context if the object is there in session (not the actual object but the proxy of it) then it will return u back and if its nt thr it will hit DB and creates a proxy in persistance context then it returns it..correct if m wrong..Thanks for reply..
org.life.java
When load is called, Hibernate checks if the object is already contained in the session. If this is true, then the object is returned, otherwise a proxy is created.
Petar Minchev
and what about get.. ?
org.life.java
Get never returns a proxy. If the object is in the session it will be returned, otherwise it will be fully initialized.
Petar Minchev
ok thankx man..
org.life.java
You are welcome:)
Petar Minchev