Skip to content
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

findOne: result of fetching too many relations [DATAJPA-589] #976

Closed
spring-projects-issues opened this issue Aug 19, 2014 · 5 comments
Closed
Assignees
Labels
in: core status: declined type: bug

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Aug 19, 2014

oaktree opened DATAJPA-589 and commented

I have one main entity called Report. I have several entities connect to Report with @ManyToMany relations. The connection is done via extra table, i.e. with @JoinTable annotation. Each relation is lazy. I have a function that fetches the report with all its relations. now, if i do fetch by fetch (i.e mark the function as @Transcational and access to each one of the property) everything works as expected. But, if I do

Report r = reportRepository.findOne(
  where(DomainSpecification.<Report>eager()).and(DomainSpecification.<Report>idIsEqual(id)));

I get all the relations as well but one of the relation (that has been connected to another table NOT by primary key) is fetching 13823 times. This means that the length of r.getProjects() is 13823 of the same Project. I attaching here the source of DomainSpecification.java / Report.java / Project.java and Keyword.java (the keyword is just to show an example for an entity that works good with this kind of fetching). Maybe one can throw some light on this issues


Affects: 1.6.1 (Dijkstra SR1), 1.6.2 (Dijkstra SR2)

Attachments:

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 20, 2014

oaktree commented

Ok, i tested this issue with JPA criteria i.e without using Spring findOne.

Report r = null;
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Report> query = cb.createQuery(Report.class);
Root<Report> report = query.from(Report.class);
ArrayList<Predicate> preds = new ArrayList<Predicate>();

DomainSpecification.<Report>eager().toPredicate(report, query, cb);
preds.add(DomainSpecification.<Report>idIsEqual(id).toPredicate(report, query, cb));
query.where(cb.and(preds.toArray(new Predicate[preds.size()])));
query.select(report);
List<Report> results = em.createQuery(query).setMaxResults(1).getResultList();

and got the same result, i.e. fetch many times the project set. So I can conclude that this bug doesn't not related to spring data and probably this is Hibernate bug? If anyone has an idea where to look for this bug i will appreciate it

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 21, 2014

Oliver Drotbohm commented

I am still not getting where you think the bug on the Spring Data side is or should have been in the first place. The number of statements executed usually solely depends on the mappings you maintain in your domain classes. I recommend reading up on defining batch sizes for lazy relations (see one example here).

For general questions prefer StackOverflow tagging your question with spring-data-jpa

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 21, 2014

oaktree commented

Hey there, thanks for reply! I thought the bug was related to Spring Data. But after doing more testing (with JPA criteria) i think it is not related anymore. There is definitely a bug because i can "simulate" eager fetch by access each lazy field and iterate over it. when doing so everything works as expect. but when trying to eager fetch all of relations. i get the same row repeating it self huge number of times (only from the report_project relation - i.e all the relations are fetching good besides that relation). I Post this in Hibernate Jira hope to get some answers

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 21, 2014

oaktree commented

p.s. thanks for the link!

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 22, 2019

Jens Schauder commented

Batch closing resolved issue without a fix version and a resolution indicating that there is nothing to release (Won't fix, Invalid ...)

@spring-projects-issues spring-projects-issues added type: bug status: declined in: core labels Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core status: declined type: bug
Projects
None yet
Development

No branches or pull requests

2 participants