Hi, i've been struggling with this for a couple of days now. I'm trying to do something very simple, write a record to a MySQL DB with a field set, have another process polling the same DB and flip the field back when its done. A very primative mailbox between two processes. Sounds simple
I'm using JPA with annotations and Hibernate on Tomcat 6 (MVC & Webflow if it matters). So i have a service class, annotated with @Service that has the methods: 1) Controller, 2) SaveValue and 3) GetValue. The controller class just delagates to both the SaveValue and GetValue. SaveValue method uses the injected EM and just does a simple persist. The GetValue method does a Query for the row written by the SaveValue.
Question #1: If i put a @Transactional with a Requires_New on just the SaveValue method i can see in the log the call to the EM which is followed by a EM close without any hibernate insert. If also put a @Transactional on the Controller method i then see the hibernate insert. Why is this? Can a method in the service class, without an @Transactional on it, call another method or for that matter another class like a DAO class that now participates in Transactions?
Question #2: If i allow the SaveValue method to completed and then call the GetValue method (no annotation) I can see the persisted value from the EM, but when i look for the new row in SQLyog, it's not there. I would have expected the Requires_New on the SaveValue to commit to the DB when the SaveValue method completed? Is there a way to force the DB update? I've tried using flush, but that didn't work.
Question #3: I've been guessing that i will need to alter the isolation level to read committed to be able to see when the value changes from the other process. I've already extended the Transaction Manager as indicated by several other web blogs since changing the isolation level throws an exception that it is not supported in the default JPA.
I've been reading books/articles for days, all of them describe each of the propagation attributes, but none of them have really explained the ins and outs of a simple transaction application where there's several layers involved. I've seen some descriptions of similar processing like auditing where a Requires_New can be used to persist the audit entry, even if the calling process rolls back...
Thanks in advance...
I'm using JPA with annotations and Hibernate on Tomcat 6 (MVC & Webflow if it matters). So i have a service class, annotated with @Service that has the methods: 1) Controller, 2) SaveValue and 3) GetValue. The controller class just delagates to both the SaveValue and GetValue. SaveValue method uses the injected EM and just does a simple persist. The GetValue method does a Query for the row written by the SaveValue.
Question #1: If i put a @Transactional with a Requires_New on just the SaveValue method i can see in the log the call to the EM which is followed by a EM close without any hibernate insert. If also put a @Transactional on the Controller method i then see the hibernate insert. Why is this? Can a method in the service class, without an @Transactional on it, call another method or for that matter another class like a DAO class that now participates in Transactions?
Question #2: If i allow the SaveValue method to completed and then call the GetValue method (no annotation) I can see the persisted value from the EM, but when i look for the new row in SQLyog, it's not there. I would have expected the Requires_New on the SaveValue to commit to the DB when the SaveValue method completed? Is there a way to force the DB update? I've tried using flush, but that didn't work.
Question #3: I've been guessing that i will need to alter the isolation level to read committed to be able to see when the value changes from the other process. I've already extended the Transaction Manager as indicated by several other web blogs since changing the isolation level throws an exception that it is not supported in the default JPA.
I've been reading books/articles for days, all of them describe each of the propagation attributes, but none of them have really explained the ins and outs of a simple transaction application where there's several layers involved. I've seen some descriptions of similar processing like auditing where a Requires_New can be used to persist the audit entry, even if the calling process rolls back...
Thanks in advance...