Skip to main content

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:

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