This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes EJB3 (JBoss 5) Problem with Persistence Context / Transaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB3 (JBoss 5) Problem with Persistence Context / Transaction " Watch "EJB3 (JBoss 5) Problem with Persistence Context / Transaction " New topic
Author

EJB3 (JBoss 5) Problem with Persistence Context / Transaction

Markus Schmider
Ranch Hand

Joined: Feb 25, 2007
Posts: 100
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

Joined: Mar 13, 2008
Posts: 34
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.

Christian Gossart
 
Don't get me started about those stupid light bulbs.
 
subject: EJB3 (JBoss 5) Problem with Persistence Context / Transaction
 
Similar Threads
Name Not Bound Exception
problem in setting mySql as default database server
JPA,/mysql/JBoss and a big head ache
Error while starting jboss(java.lang.ClassNotFoundException: No ClassLoaders found for: com.mysql.j)
Throw an exception dosnt cause to rollback when it is not