micdcar
micdcar

Reputation: 171

Struts 2 execAndWait + Spring transaction management integration

I'm executing an action that takes a while, so I'm using a custom Struts' ExecuteAndWaitInterceptor. I launch a custom BackgroundProcess that opens a transaction before invocation, and closes it after invocation.

The action I'm calling uses a service that has the following Spring's transaction advice:

<tx:method name="search" propagation="REQUIRED" />

However, when I execute this action, I get the following error:

Could not open Hibernate Session for transaction; nested exception 
  is org.hibernate.TransactionException: nested transactions not supported

I'm guessing this happens because Spring is unable to see the transaction that was opened in BackgroundProcess and tries to open a new one. Thus, this error occurs.

How can I configure my BackgroundProcess so that it opens a transaction that is seen by Spring?

Or how can I stop Spring from interfering when BackgroundProcess is being ran?

Upvotes: 0

Views: 156

Answers (1)

Roman C
Roman C

Reputation: 1

Spring managed transactions should be configured for spring beans. You can't manage a transaction on beans that were created without context.

So you either have to configure Spring to use the managed instance of the bean or exclude it from transaction advice.

Upvotes: 1

Related Questions