- Replies:
- 0
- Words:
- 5309

application.properties:
spring.datasource.url=jdbc:firebirdsql://localhost:3050/yourdb
spring.datasource.username=sysdba
spring.datasource.password=masterkey
spring.datasource.driver-class-name=org.firebirdsql.jdbc.FBDriver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.hibernate.dialect.FirebirdDialect
Spring Boot automatically manages the connection pool using this configuration@EnableTransactionManagement annotation to your main class:
@SpringBootApplication
@EnableTransactionManagement
public class FirebirdApp {
public static void main(String[] args) {
SpringApplication.run(FirebirdApp.class, args);
}
}
This enables declarative transaction handling across your applicationYou can define transactions in service classes using the @Transactional annotation:
@Service
public class EmployeeService {
@Autowired
private EmployeeRepository repo;
@Transactional
public void updateSalaries(Long deptId, double increment) {
repo.findByDepartmentId(deptId)
.forEach(emp -> emp.setSalary(emp.getSalary() + increment));
}
}
All updates inside this method will commit as one unit of work. If an exception occurs, the entire transaction rolls back automaticallyYou can customize rollback behavior:
@Transactional(rollbackFor = Exception.class)
public void transferFunds(Account from, Account to, double amount) {
from.debit(amount);
to.credit(amount);
repo.save(from);
repo.save(to);
}
If any exception is thrown, both save() operations will roll back, keeping the data consistentCreate integration tests to verify transaction behavior:
@SpringBootTest
@Transactional
public class TransactionTest {
@Autowired
private EmployeeService service;
}
Spring Boot will automatically start and rollback transactions during tests
image quote pre code