Q:
Quote:
Will get() hit the DB if the object has already been loaded in that Session?
A:
Quote:
No.
This seems dangerous (and annoying) to me. Basically, the behavior of the get() method varies per object based on whether or not it has already been resolved via load(). This matters most when the object has been deleted. But I don't see how the behavior of the get() method can be improved. Tell me whether or not using the following code in my Hibernate facade seems like a good practice:
Code:
public Object get(Class clazz, Serializable id)
{
Object entity = session.get(clazz, id);
if (entity != null && isProxy(entity))
{
evict(entity);
entity = get(clazz, id);
}
return entity;
}
This way, get
always returns an object or null,
never a proxy, especially for an object that has been deleted.
I appreciate the feedback.