-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Tricky Cache problem
PostPosted: Wed Jun 30, 2010 4:53 am 
Newbie

Joined: Tue Mar 24, 2009 1:09 pm
Posts: 14
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.