The Hibernate JavaDoc states that Session.update(Object o)
would raise an exception if there's already a persistent instance of o
, right?
If there is a persistent instance with the same identifier, an exception is thrown.
However, the following code doesn't throw anything when I run it. And I think it should!
Email email = new Email("andre", "girafa", "hi");
Session session = factory.openSession();
Transaction tx = session.beginTransaction();
session.save(email);
session.update(email);
session.update(email);
tx.commit();
// didn't throw... Let's try again
tx = session.beginTransaction();
session.update(email);
session.update(email);
tx.commit();
session.close();
// still nothing! :(
As you can say, twice I try to do multiple update()
s, but still Hibernate's taking easy on me.
Anybody has a hunch why?
EDIT: it seems that it would only throw if another equivalent object, for instance, email2
with the same ID as email
. I guess the documentation was kinda sloppy there.