I'm seeing some behavior with Hibernate I did not expect. Basically, I load an entity instance from the database, apply some changes to the fields, start a transaction, then run a (select) query; at this point the changes to the entity are being run against the database. I know this because I get a constraint violation (which I was trying to prevent via the query). I haven't called saveOrUpdate() on the modified entity at this point however, so I did not expect it to be persisted. Here's a simplified version of the code:
Code:
Account account = accountDao.loadById(accountId);
account.setEmail("existing-email@example.com");
// Start transaction via Spring annotation
List existing = accountDao.findByEmail(account.getEmail());
// Above line causes org.postgresql.util.PSQLException:
// ERROR: duplicate key violates unique constraint "account_email_key"
Can someone give me some insight as to what is happening here?
Running Hibernate 3.3.1.GA within JBoss 5.0.1.GA.