java - Why do I get N+1 select queries when lazy loading many-to-many entities -


I just hope to have a SQL query, but I'll go to the N + 1 selected network. I really do not understand why there is a problem in detail here:

I have a single unit "player":

@ entity @Table (name = " Player_ref ") Public class PlayerRef {// Creator etc ... @OptimisticLock (Excluded = true) @LazyCollection (LazyCollectionOption.TRUE) @ManyToMany (fetch = FetchType.LAZY, mappedBy =" playerRefs ") set public & lt; Player & gt; Millplayer () {Return Player; }}

and a class player:

  @Entity @Table (name = "player") public class player {// constructor etc ... @OptimisticLock (Excluded = true) @LazyCollection (LazyCollectionOption.TRUE) @ManyToMany (fetch = FetchType.LAZY) @JoinTable (name = "cr_player_ref_player", joinColumns = {@JoinColumn (name = "player_id", unique = true)}, InverseJoinColumns = {@JoinColumn (name = "player_ref_id"}} Private set & lt; PlayerRef & gt; GetPlayerRefs () {this.playerRefs;}}  

Now, in my program I To access all the playerRef entities using the following HQL query:

  query playerRefQ = session.createQuery ( PlayerRefOnly (true); PlayerRefQ.setParameter ("sports", game); @SuppressWarnings ("uncontrolled") list & gt; PlayerRef & gt; AllPlayerRefs = playerRefQ.list ();  

It selects statements in N + 1:

1)

  select playerref0_.id as id1_21_0_. Player_ref playerref0_  to 

n times)

  players0_.player_ref_id player_r2_21_0_, player_i1_34_0_player players0_.player_id, id1_19_1_peak as player1_.id , ... from Cr_player_ref_player player0_iner betadata.player player 0_. players_player_id = player1_i Where players0_player_ref_id =?  

This (again) is very unpredictable, because I thought the collection is lazy and the reef set of players of each player should be a hibernate-proxy.

Nobody knows how can I load only player reef institutions without the players loading the players? In the case of my use I need all the players, but not the players concerned.

In one of my previous questions it was suggested that the string (or method) of the player reef or the player can be written in some way, affiliates are not the case. N + 1 questions All players are correct when they reach the list of reef institutions.

Note:

  1. This is a follow-up question

  2. There is a similar question without any question:

To play with the batch size and the received mode, this is the reference link which will tell you how to remove the issue that you choose N + 1

Hope this will be helpful


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -