-
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
Error related with JPA EntityGraph in Spring Boot 3.4.0 #3709
Comments
This looks pretty much like a bi-directional mapping issue
I can reproduce the issue with the following JPA code: long userId = 1;
Payment payment = new Payment();
var invoice = new Invoice();
invoice.setId(1L);
payment.setInvoice(invoice);
AppUser appUser = new AppUser();
appUser.setId(userId);
payment.setCreatedFrom(appUser);
entityManager.persist(payment);
Invoice invoiceLoaded = (Invoice) entityManager.createQuery("SELECT i FROM Invoice i WHERE i.id = ?1")
.setParameter(1, invoice.getId()).getSingleResult();
jakarta.persistence.EntityGraph<StudentFeesToInvoice> entityGraph = entityManager
.createEntityGraph(StudentFeesToInvoice.class);
entityGraph.addSubgraph("invoice")
.addSubgraph("payments")
.addAttributeNodes("createdFrom");
// failure happens here
entityManager.createQuery("SELECT s FROM StudentFeesToInvoice s WHERE id = ?1")
.setHint("jakarta.persistence.fetchgraph", entityGraph)
.setParameter(1, invoiceLoaded.getId()).getResultList(); I don't think that Hibernate can do much especially when being told to use eager fetching instead of lazy-loading proxies. In any case, please file a bug report with the Hibernate issue tracker as the |
Summary:
I originally posted this as a Spring Boot issue, but since this is JPA/Hibernate related, maybe it belongs here.
After upgrading to Spring Boot 3.4.0 (Hibernate 6.6.2-Final), there is a Hibernate related error when a transactional method, after saving a row, tries to retrieve some data from a repository method using
EntityGraph
. This worked in Spring Boot 3.3.5 (Hibernate 6.5.3-Final). As it is mentioned in the original issue, this has to do with using non-managed objects but it is almost impossible to identify all the cases, so i trying to check if there is a way to get the functionality in the previous version (without downgrading hibernate)Details:
TestController
callsaddPayment
fromTestService1
. This method is transactional.This method calls the
save()
method of a repositoryThen it calls another service
TestService2
method2
This method performs a query using a repository and then another query from another repository which uses
EntityGraph
.The exception is
While trying to reproduce the issue i got another exception, but not constantly
If we change the version of Spring Boot to 3.3.5, this works
Steps to reproduce:
Run the attached project using postgres as database.
errorCheck.zip
Access "http://localhost:8080/test" and an exception will be produced
If we change the Spring Boot version to 3.3.5 the endpoint will return the response "1"
Environment:
Spring Boot version: 3.4.0
Java version: 21
Operating System: Windows 11
Attachments
Sample project to reproduce the error
The text was updated successfully, but these errors were encountered: