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
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
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
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
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