micronaut-projects / micronaut-projects/micronaut-sql
TransactionRequiredException thrown although TransactionalAdvice annotated
- Dominant language
- Java
- Stars
- 83
- Forks
- 49
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 22
Description
### Expected Behavior
The deletion in the database should work as expected.
### Actual Behaviour
A TransactionalRequiredException is thrown
### Steps To Reproduce
1. Use testcontainers with postgresql 11.8
2. Write a Micronaut-Test testing the following method
```@TransactionalAdvice
@Override
public int deleteAllSlugsLikeAndOlderThan(String query, Instant date) {
String qlString = "DELETE FROM ArdmResultEntity AS s WHERE s.slug LIKE CONCAT('%', ?1, '%') AND s.createdAt < ?2";
Query query = entityManager.createQuery(qlString)
.setParameter(1, query.trim())
.setParameter(2, date);
int deletedRows = 0;
try {
deletedRows = query.executeUpdate();
} catch (Exception e) {
log.error("Deletion was not successful", e);
}
return deletedRows;
}
```
4. TransactionRequiredException is thrown
### Environment Information
_No response_
### Example Application
_No response_
### Version
3.5.2
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the deletion method with PostgreSQL 11.8 in a Micronaut test, using the shown @TransactionalAdvice method and EntityManager query. Check where the transaction is expected to begin before executeUpdate(), then verify the behavior with the testcontainers setup. Done means the delete executes without TransactionRequiredException and the expected rows are removed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, postgresql
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100