File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB3 (JBoss 5) Problem with Persistence Context / Transaction

 
Markus Schmider
Ranch Hand
Posts: 119
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am experimentig with JPA and I have difficulties to reproduce an example taken from JavaMagazin 9/09 about the ECB Pattern.
JBoss 5.1.0 GA, MySQL 5.0



The "boundary" (facade)





The Warehouse Bean persists the order. This works like expected:




However the DeliveryService modifies the order:




Since the transaction should be still running, I expect that order is still in the persistence context and that the changes made by the DeliveryService should be automatically persisted. However they never arrive in the database.

Do I get the whole concept or persistence context wrong? Or is there some bug in my code?






 
Christian Gossart
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marcus,

Seems the checkout method is bugged if you are using it with a brand new Order instance: when using the merge method of the EntityManager with a new entity instance, this instance remained detached while a new managed instance is created and stored in the persistence context. It is this managed instance that is returned from the merge call. To get a hold on it, use the following code instead:



Then the Order instance returned from the checkout method is managed, and any change done by the deliver method will produce an sql update when the transaction commits.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic