5

Unfortunately, i cannot find answer on my question. This question appears when i get incorrect data using method findOne(ID id).

My project contains three entities each of them contains JPA unidirectional association @OneToMany.

Example: Class A (contains List of Class B) -> Class B (contains List of Class C) -> Class C

Method findOne(ID id) return duplicates of Class B in List which relate to Class A. Unlike in the previous method, findById(long id) return correct number of related entities. After some research I found out that findOne(ID id) use Left Outer Join in sql query.

I want to understand, there is the issue in findOne(ID id) method or it works properly.

Environment: Spring Data JPA 1.8.0.RELEASE, Hibernate 4.3.8.Final, MySQL

John Conde
  • 217,595
  • 99
  • 455
  • 496
VlasovArtem
  • 306
  • 5
  • 6
  • As outlined in the ticket you created [here](https://jira.spring.io/browse/DATAJPA-709), the symptoms you see have nothing to do with `findOne(…)` at all. Whether associations return duplicate items solely depends on the persistence provider and your association mappings. – Oliver Drotbohm Apr 26 '15 at 11:26
  • I've encountered the same issue. This answer https://stackoverflow.com/a/18753303/1407926 on an other post helped to understand what happend and why its happening. The consequence from that behaviour would be to use sets for one-to-many relationships and not lists right @OliverGierke? – conscience Jun 13 '17 at 20:48

0 Answers0