-->
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.  [ 2 posts ] 
Author Message
 Post subject: Think JPWH has a mistake
PostPosted: Thu Feb 12, 2009 5:49 pm 
Newbie

Joined: Thu Feb 12, 2009 5:37 pm
Posts: 1
I think Java Persistence With Hibernate has a mistake on p423. It has a code sample that looks something like:
Code:
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
Item item = em.find(Item.class, new Long(1234));
tx.commit();
item.setDescription(...);
tx.begin();
User user = em.find(User.class, new Long(3456));
user.setPassword("secret");
tx.commit();
em.close();


And then it says:
Quote:
...in the second transaction, you not only load a User object, but also update the modified persistent item when the second transaction is committed (in addition to an update for the dirty
user instance).


But item.setDescription(...) is not called within the second transaction in the example code, item.setDescription(...) should be moved one line down. Is this correct?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 8:18 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
No its not a mistake. What it means is the item.setDescription(...); happed after the transaction is commited and so item is dirty (ie. not in sync with DB). So the next commit will commit the modifications done to the User object and the update done to the "dirty" item.

_________________
Regards,
Litty Preeth


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

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.