manil wrote:
MyObject myObject = (MyObject)session.load(MyObject.class, myObjectId);
1. Since class-level lazy loading is enabled for MyObject, Hibernate is giving you a proxy for the object with
myObjectId (it's not even hitting the database).
manil wrote:
session.save(myObject);
Now you are passing an object that is already persistent to Session.save(), which doesn't make sense. You only need to save() it the first time. Then when you load() it Hibernate keeps tracks of what's changed and flushed it back to the database. The exception says "Uninitialized proxy" because of what I explained in (1).
To fix your code, just remove the call to session.save() and do myObject.setSomething(). You should probably read the section about Hibernate object lifecycle in the Hibernate in Action book.