Error flush transaction
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
### Expected Behavior
Since migration 6 (maybe 7.0.0-RC1) to 7.0.0, I have an error hibernate when I'm trying save two domains in the same transaction :
```groovy
Utilisateur.withNewTransaction {
//Creation utilisateur admin
if (Utilisateur.countByUsername("test") == 0) {
Role roleAdmin = Role.findByAuthority("ROLE_ADMIN")
Utilisateur userAdmin = new Utilisateur(username: "test", password: "test", email: "test@domain.fr").save(flush: true, failOnError: true)
new UtilisateurRole(utilisateur: userAdmin, role: roleAdmin).save(flush: true, failOnError: true)
}
}
```
Error :
```
org.springframework.orm.hibernate5.HibernateObjectRetrievalFailureException: No row with the given identifier exists: [org.monprojet.Utilisateur#13]
at org.springframework.orm.hibernate5.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:238)
```
### Actual Behaviour
_No response_
### Steps To Reproduce
1) Try to create new relation between two domain in `Domain.withNewTransaction`
2) Test OK ✅
3) Modify `UtilisateurRole` to add constraints with `withNewSession`
4) FAIL ❌
### Environment Information
* ~Database postgres~
* ~jdbc connector version : 42.7.8~
### Example Application
https://github.com/Noirtam/grails-grails702-issue15224
### Version
7.0.0 / 7.0.2
Contributor guide
Research direction
Start with the example application linked in the issue and reproduce the failure in the `Utilisateur.withNewTransaction` flow. Compare the behavior before and after adding constraints with `withNewSession` to the `UtilisateurRole` relation. Done means creating the two domains in one transaction no longer raises `HibernateObjectRetrievalFailureException`.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100