-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DeleteAll after Spring Boot 3.4 update creates TransientObjectException #3737
Comments
I'm able to reproduce the issue by using the entity manager directly: @AfterEach
void tearDown() {
EntityManager entityManager = emf.createEntityManager();
entityManager.getTransaction().begin();
List resultList = entityManager.createQuery("FROM DocumentationUnitDTO").getResultList();
for (Object o : resultList) {
entityManager.remove(o);
}
entityManager.getTransaction().commit();
entityManager.close();
}
@Test
void test_generateAnObjectAndDeleteItInTearDown() {
DocumentationUnitDTO documentationUnit = new DocumentationUnitDTO();
EntityManager entityManager = emf.createEntityManager();
entityManager.getTransaction().begin();
entityManager.persist(documentationUnit);
entityManager.getTransaction().commit();
ProcedureDTO procedure = new ProcedureDTO();
entityManager.getTransaction().begin();
entityManager.persist(procedure);
entityManager.getTransaction().commit();
DocumentationUnitProcedureDTO documentationUnitProcedure = new DocumentationUnitProcedureDTO();
DocumentationUnitProcedureId primaryKey = new DocumentationUnitProcedureId(documentationUnit.getId(),
procedure.getId());
primaryKey.setRank(1);
documentationUnitProcedure.setPrimaryKey(primaryKey);
documentationUnitProcedure.setDocumentationUnit(documentationUnit);
documentationUnitProcedure.setProcedure(procedure);
documentationUnit.getProcedures().add(documentationUnitProcedure);
entityManager.getTransaction().begin();
entityManager.persist(documentationUnit);
entityManager.getTransaction().commit();
entityManager.close();
} However, if you run your test method enclosed in a transaction (e.g. annotating the test method with Downgrading to Hibernate 6.5 causes the issue to also disappear. I consider this a Hibernate bug worth reporting to the Hibernate team. |
Thanks! I look for the error in my hibernate test (I do this also and I don't get an error.) I will report it to the hibernate team. |
Sorry. I have generate first a stackoverflow article, but I think because it's probably a bug I will reported it here also.
https://stackoverflow.com/questions/79336531/deleteall-after-spring-boot-3-4-update-creates-transientobjectexception
We try to update our application to Spring Boot 3.4 and have with this some problems. One of it let's failed some of our integration tests. Because our application has a little complicated model I generate a small example which shows the problem.
https://github.com/rvp-c/springboot34_deletecascade
Some explaination for the model we use. We have to objects - DocumentationUnitDTO and ProcedureDTO which use a many-to-many relation. So far so easy. Problem the main object (DocumentationUnitDTO) needs an order. This we have to put into the join table (DocumentationUnitProcedureDTO).
The problems seems to be in the ProcedureDTO which have a reference to the DocumentationUnitDTO which is annotated with:
The generation works fine. But the deletion seems to do a cascade from DocumentationUnitDTO -> ProcedureDTO -> DocumentationUnitDTO. (debugging of the exception)
Same code works with spring boot 3.3 without errors.
What did I try
@Transient
everything works fine.The text was updated successfully, but these errors were encountered: