Hi guys,
I was debugging some code and noticed that calling session.get() returns a proxy if the proxy exists in the persistence context. This came as a bit of a surprise, especially after reading HiA (that's addressed here
http://forum.hibernate.org/viewtopic.php?t=941435).
While trying to understand what was going on, I traced through the Hibernate code and found that a database hit was actually incurred, and the loaded entity set to the implementation field of the lazy initializer of the proxy.
So here's what I can't figure out. If the database hit is incurred anyway, and if the object is loaded, why doesn't get() immediately return the entity instead of a proxy to it? Is there any reason not to?
Thanks,
mers
Hibernate version:
3.2.6
Code:
sessionFactory.getCurrentSession().load(Car.class, 1);
sessionFactory.getCurrentSession().get(Car.class, 1);