Annotation-Based
Hint
This article is generated by AI translation.
Important
Interceptors are required for annotation-based transactions, so the exact annotations depend on the framework:
- Spring transaction annotations: see details
- Solon transaction annotations: see details
Example with Hasor or Guice
import net.hasor.dbvisitor.transaction.Transactional;
public class TxExample {
@Transactional(propagation = Propagation.REQUIRES)
public void exampleMethod() {
...
}
}
Plain applications
Plain applications do not use bytecode enhancement; annotations still work with helper support.
Object enhancement
DataSource dataSource = ...
TxExample txExample = ...
// Enhance txExample by creating a proxy that weaves in interceptors.
txExample = TransactionHelper.support(txExample, dataSource);
txExample.exampleMethod(); // proxy handles the @Transactional annotation