0

I use hibernate 4.3.6, spring data jpa 1.9

I have 2 entity: DocumentOrder and OrderChain. OrderChain have ManyToOne DocumentOrders; DocumentOrder doesnt have link.

public class OrderChain {
   @ManyToOne(fetch = FetchType.EAGER)
   private DocumentOrder documentOrder;
}

When i do query "SELECT oc FROM OrderChain oc WHERE ..." i have many requests to database(I look in console).

I find similar topics:

preventing N+1 selects in JPA

FetchMode join makes no difference for ManyToMany relations in spring JPA repositories

JPA eager fetch does not join

but i dont know how solve it without adding join fetch in my Query.

edit: I try add @Fetch(FetchMode.JOIN) to documentOrder, but it doesnt make any effect.

Thanks

Community
  • 1
  • 1
zam
  • 328
  • 1
  • 2
  • 11
  • This link will be helpful :https://dzone.com/articles/how-identify-and-resilve-n1 – rupesh_padhye Oct 16 '15 at 12:46
  • @rupesh_padhye i have many queries and add for all "join" require many time. Can i do some changes in hibernate config or in model for fix it? – zam Oct 16 '15 at 12:54
  • There are plenty of JPA implementations and not all do "suboptimally queries", so suggest you try a different one – Neil Stockton Oct 26 '15 at 08:07

0 Answers0