Featured post
java - Using and controlling Spring transactions within Struts 2 actions -
hey guys, have been working while on project following components:
- struts2.1.8.1,
- spring 3.0.3
- jpa 2.0,
- hibernate 3
i using spring's entitymanager magic... i'm having problems dealing transactions inside actions. instance, setting values on persisted object in several methods within class, , want able rollback
if validate
method finds validation error, or commit
these changes otherwise. have spent quite long time reading half of internet comprehensive explanation. unfortunately, no complete examples exist (at least similar stack).
i have stumbled thread on mailing list: @transactional spring annotation in struts2 action not work. message i'm linking @ seems have pretty simple , straightforward solution, using transactioninterceptor
trick seems... problem i'm not finding useful information regarding interceptor.
anyone here has experience technology , can spare tip , link or 2 on how use spring transactions inside struts2 actions?
thanks!
- edit 1 -
i have set test project if interested, download file , try out (or inspect it). thanks!
generally, controllers/actions/backing beans/etc don't handle transactions. actions web-part of back-end code - should concerned gathering request data, , sending response data. logic (including database access) should done in layer. e.g. service layer. create bean, inject in action, , make work - userservice.register(user)
. configuring transactions on service layer should trivial since both in spring documentation , in countless examples:
<tx:annotation-driven />
, @transactional
(btw, make sure have <tx:..>
now, might causing issue. if works, not invalidate suggestion service layer)
- Get link
- X
- Other Apps
Comments
Post a Comment