I'm working on a system where I need to store processed data across approximately 30 tables in a SQL Server database. For frequently used tables, I'm using JPA, while the majority of the insertions are handled using JDBC due to performance and control needs.
Currently, I wrap the entire operation in a Spring @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) annotation. This approach ensures that any failure during the operation rolls back all the changes — which is good. However, it locks all the involved tables until the full transaction completes, which negatively affects scalability and performance.
What I need:
- A way to persist data across multiple tables efficiently.
- Maintain transactional integrity — if any part of the process fails, the entire operation should roll back and leave the database in the exact previous state.
- Minimize long-held locks or table blocking that affect scalability.
Questions:
- Is there a better way to manage transactions when working with a mix of JPA and JDBC across many tables?
- Can
@Transactionalbe used in a smarter way (e.g., splitting into smaller units with proper rollback)? - Would programmatic transaction management, nested transactions, or custom rollback logic be more suitable here?
- Are there any best practices for this kind of multi-table write operation to balance consistency and performance?
I’m looking for a scalable and clean approach to ensure rollback behaves exactly as expected, without locking the entire database section for the duration of the transaction.