graz wrote:
Secondly, failing the first question, is there a good way to find out whether the object exists in the persistent store before I call these operations. As I will be using the same session, the documentation says I shouldn't try a session.load(Class, Serializable) to confirm existence, and indeed if I try this I get an exception on the following update saying "Another object was associated with this id (the object with the given id was already loaded)"
example code:
Object result = session.load(target.getClass(), target.getId());
session.update(target);
However the documentation says to use find(), which I am assuming is session.find(String). If I build up a query string manually and then use this however I get exactly the same error.
example:
List result = session.find(query);
if (result.size() > 0)
{
session.update(target);
}
Am I doing something monumentally dumb here and does anyone know what I need to write to do this?
Thanks for any help.
This is exactly the same problem I'm having and I just can't seem to solve it. Did you? Anyone else have insight? I read the "Advanced Problems" FAQ about it but how else are you supposed to retrieve an object, make modifications to it and update the thing? I am using collections (and updating them), and I am opening the session just before the update() and closing it right afterward. I'm stumped!
Scott