-
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
Weird behavour when using bidirectional oneToMany in combination with jpa postload #3750
Comments
Have you verified the behavior is different when using Hibernate through |
I have tried to use EntityManager and the bug still appears. Here is the code that I have used: @SpringBootTest
class HibernatePostloadBugExperimentApplicationTests {
@Autowired
private EntityManager entityManager;
@BeforeEach
@Transactional
public void setup() {
entityManager.createQuery("DELETE FROM Parent").executeUpdate();
entityManager.createQuery("DELETE FROM Child").executeUpdate();
}
@Test
@Transactional
void contextLoads() {
Parent parent = new Parent();
entityManager.persist(parent);
entityManager.persist(new Child(1, parent));
entityManager.persist(new Child(2, parent));
entityManager.persist(new Child(3, parent));
entityManager.flush();
entityManager.clear();
List<Child> children = entityManager.createQuery("SELECT c FROM Child c").getResultList();
assertEquals(3, children.size());
}
} Let me know if that is what you meant. |
Yes, that's what I was looking for. Please note that your code is slightly different (posting the reproducer from your GitHub repo): @Test
void contextLoads() {
Parent parent = new Parent();
parentRepository.save(parent);
childRepository.save(new Child(1, parent));
childRepository.save(new Child(2, parent));
childRepository.save(new Child(3, parent));
List<Child> children = childRepository.findAll();
assertEquals(3, children.size());
} All |
Oops, you are right, sorry. I have updated it, and the bug still appears. Here is the code: @SpringBootTest
class HibernatePostloadBugExperimentApplicationTests {
@Autowired
private TransactionTemplate transactions;
@Autowired
private EntityManager entityManager;
@BeforeEach
public void setup() {
transactions.executeWithoutResult(s -> {
entityManager.createQuery("DELETE FROM Child").executeUpdate();
entityManager.createQuery("DELETE FROM Parent").executeUpdate();
});
}
@Test
void contextLoads() {
Parent parent = new Parent();
transactions.executeWithoutResult(s -> entityManager.persist(parent));
transactions.executeWithoutResult(s -> entityManager.persist(new Child(1, parent)));
transactions.executeWithoutResult(s -> entityManager.persist(new Child(2, parent)));
transactions.executeWithoutResult(s -> entityManager.persist(new Child(3, parent)));
List<Child> children = transactions.execute(t ->
entityManager.createQuery("SELECT c FROM Child c").getResultList());
assertEquals(3, children.size());
}
} |
Hello,
I',m unsure if this is project is the correct place to report the following behavour I've observed, please let me know if I should report it to another github project.
With the latest spring boot 3.4.x version, I have observed the following problem in my springboot project that uses spring data jpa to persist againsts postgres database. I have created a small springboot project to reproduce this bug github project
mvn docker:start -Pdocker
The test throws an exception because of during the postload in the list of children the first child's fields are null, interestingly other children have fields with values as expected, please see screenshot:
I have added a feature branch in my project revert-to-old-springboot where I use spring boot 3.3.x instead and the test is successful and the bug does not appear.
The text was updated successfully, but these errors were encountered: