This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Declarative Transaction support

Hello, I've been writing a Struts web application that uses Spring declarative transaction support and OJB as the ORM tool.

All of my services in my application are using the PROPAGATION_REQUIRED keyword for the transaction manager. A Struts action may call one or more services to complete it's work.

I've run into some database locking issues and after logging SQL Statements using the p6spy driver, I've found that when I do 3 web requests, I get 8 database transactions. I would have thought that each web request would have a single database transaction.

I thought the first service within a web request would see that there was no transaction and it would start one, then other services within the same request would see that a transaction has started and participate in it, rather than starting a new one.

How the transactions are partitioned depends on what class you have proxied and how you have implemented your DAOs. The first thing to check when having transaction problems is that the proxy is assembled correctly and that you are actually using the proxy and not the proxy target. In code you can verify that you are using the a proxy with AopUtils.isAopProxy().

Can you post your ApplicationContext XML along with any business interfaces, that should give me enough to go on

Comment

My application context file and the actionservlet files are huge. I'll just send pieces. If you need the whole thing, I can post them, but they are pretty big.

Here is an update. I met with our dbas and they tell me that sql that I thought would be in the same connection are happening on different connections - therefore they can't share the same transaction and this is causing the problem. If they would all happen on the same connection, we would be in business.

Here is the section in my actionServlet for the action that calls the service.

public interface FormatService {
// Look up information about the user's campus
public PhysicalCampus getPhysicalCampus(String campusCd);

// Get the customer profiles to list on the screen
public List getAllCustomerProfiles();

// Get disbursement numbers to list on the screen
public List getAllDisbursementNumberRanges();

// Find out if the format is already running somewhere
public Date getFormatProcessStartDate(String campus);

// Mark the process log so a format only happens once per campus. Mark all the
// payments that will be formatted and return a summary. attachments will be Y, N or null for both.
public List startFormatProcess(User user, String campus, List customers, Date paydate, boolean immediate,
String attachments);

// Mark the process as ended.
public void endFormatProcess(String campus);

I am at a loss here, everything seems in order. However, the only thin I can think of is that this might be an issue with transactions spread across OJB and JDBC, I'm not really sure how that works.

I do have one more question though: are you invoking methods on multiple transactional proxies and looking for the transation to span the different proxies because it doesn't. When you first call a method on a transactional proxy you start the transaction. Any other methods called in the control flow of the starting method will execute under the transaction. When the starting method ends so does the transaction. If this is the pattern you are following then that is likely where your problem lies. You need to encapsulate each logical transaction into a metho on your transaction proxy.

If this doesn't help I will post this on the dev list and hopefully someone will know the answer.