What differs between @Transactional and programmatic transactions?
@Transactional is declarative and proxy-based; TransactionTemplate gives explicit control. See examples, a comparison table and when to use each.
Spread Your Knowledge. Questions with answers, tutorials and articles, newest first.
@Transactional is declarative and proxy-based; TransactionTemplate gives explicit control. See examples, a comparison table and when to use each.
Spring wraps beans in proxies where TransactionInterceptor manages transactions. Learn pointcut advisors, advice ordering, and when AspectJ mode is needed.
@EnableTransactionManagement activates @Transactional support through proxies. Covers attributes, Spring Boot auto-configuration, rollback rules and pitfalls.
@AfterThrowing runs Spring AOP advice when an advised method throws an exception, ideal for logging and alerts. See syntax, examples and its limits.
Use @AfterThrowing to log or alert on failures and @Around to translate or recover from exceptions without touching business code.
@AfterReturning runs advice after a method returns normally and can read its result. See pointcut syntax, the returning attribute and proxy limits.
Write @Around advice in Spring AOP to wrap method calls for timing, caching and retries, and avoid the proxy pitfalls that stop advice from running.
@Before runs advice just before a matched Spring bean method. See pointcut syntax, JoinPoint arguments, ordering with @Order and when to use @Around instead.
Define Spring AOP pointcuts with @Pointcut and execution expressions, reuse them across advice, and avoid common proxy pitfalls like self-invocation.
@Aspect marks a class as a Spring AOP aspect for logging, security or transactions. Learn how to set it up, the advice types and its proxy limits.
Add aspect-oriented programming to a Spring app with aspects, advice and pointcuts, and see why self-invocation and final methods are not advised.
@EnableAspectJAutoProxy activates @Aspect-based AOP in Java-configured Spring apps. See how to set it up, write pointcuts, order aspects and avoid common pitfalls.
Add created and modified audit fields in Spring Data JPA with AuditorAware and Spring Security, and use Hibernate Envers when you need full revision history.
Tune the pool, retry only transient failures and map the rest to a clear 503 response when Spring cannot reach the database.
JDBC gives you direct control over SQL, while JPA maps objects to tables for you. Compare them with code examples and learn when to choose each.
Map query results to objects in Spring JdbcTemplate using a RowMapper lambda, a reusable class, DataClassRowMapper for records, or a ResultSetExtractor for joins.
Propagation.NESTED runs a method inside the caller's transaction using a savepoint, so a failure can be rolled back without losing the rest of the work.
JdbcTemplate runs SQL without the JDBC boilerplate. See queries, RowMapper, batch updates, JdbcClient and transaction handling in Spring.
Enable Hibernate JDBC batching, save in chunks and clear the persistence context. Learn when JdbcTemplate or Spring Batch is the better fit for bulk work.
It marks a transaction as read-only so Spring, Hibernate and the database can skip work like dirty checking. It is a hint, not a guard.