Hi All
I am implementing my app very similar to this tutorial at
http://struts.apache.org/2.0.14/docs/struts-2-spring-2-jpa-ajax.html
Some of my action classes attempt to persist data into 2 or more tables(i.e: 2 or more spring beans declared in the applicationContext.xml)
My applicationContext.xml is pretty much the exact same as that tutorial:
My issue is that I sometimes need 1 action class to invoke and update data in 2 or more tables.
Example from above. userAdministrationAction has a save() which will update the projectServiceImpl & userProjectServiceImpl beans by calling there respective service layers.
I need to find out how to do 2 things:
1) Since the save() in the userAdministrationAction calls 2 different service layers, how can I put this save() in a transaction? So that if the call to the 2nd service layers fails, it will roll back the call to the first service layer? I have researced all over the web and i cant seem to figure it out. The example I mentioned above at that URL does not have this scenario.
My userAdministrationServiceImpl class is transactional(spring will make sure its methods runs inside a transaction). However, since its the action that calls these service methods, the action itself is not in a transaction.
How can I implement this?
2) When an action calls multiple services, I used the shared entity manager to ensure its set on the services before calling the services methods. I have a feeling I am doing this incorrectly at the moment. What I currently do is as follows:
In userAdministrationAction:
If I do not implement the line above, and try and access methods in other services, I get a null pointer exception. This happens because the EntityManager
is null.
Is there a better way of doing this than what I am doing at the moment?
I would appreicate help in those 2 questions. It would really help me move on considerably as I am stuck at the moment.
kind regards
Mick