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.

Commons Transaction

Jan 3rd, 2005, 01:03 PM

Has anyone used the newly promoted Commons Transaction for dealing with file writing/reading in a transaction setting? I have a few service methods that write or delete a file then stick the file name into a database. I have rollback working great for database exceptions where it can't write the filename, but I have no ability to delete the file if there is a failure writing its name to the database. Is there a built in spring mechanism for this or should I pursue creating a type of transaction aspect thing with this commons Transaction?

For this specific usecase, you can create a org.springframework.aop.ThrowsAdvice and hook it as a preInterceptor into your TransactionProxyFactoryBean. The advice should be responsable for files deletion if a DataAccessException / MyApplicationException is thrown.
HTH