Or is it the cache...
I have a JUnit runs with a transaction.
The test tries to ensure that a many-one relationship with no cascade on update does in fact only update the parent and not the child.
I have some test code that generates whichever entity I want, within the transaction, so it gets rooled back on completion of the test.
1. So I initially create:
User1-->Client1
2. I then create a new Client called client2 and assign to User1 so we have
User1-->Client2
3. I then change the property called "name" on Client2 to the string "foo" (from somthing else)
4. I then persist (update) User1
5. I read User1 back by selecting on its code em.createQuery("SELECT User FROM User AS user WHERE user.code = :code"); - which is not its hibernate id, so Im not performing a load (jpa find), but a select on a property (which is unique), I believe this wont use the first level cache.
I check to see if we have Client2 attached to User1 rather than Client1 - which it does - Correct. I check to see if Client2 name is NOT equal to "foo" because the Client2 itself shouldnt have been update becuase the update is not cascaded. It WAS set to "foo" !!! which fails my test.
However, if I read back User1 by doing a entityManager().find(User.class, id); the attached client Is Client2 but it does not have the update name, which is what should happen.
So question is why do I get Client2, with its updated name when I do a select on its User?
|