Hibernate performace - to many select queries in console log
<p>I think that I have problem with hibernate performance. Maybe I am doing something wrong. 
I am using Spring 4 and Hibernate 4.
I have two tables in database, Driver and Fleet connected ManyToMany. Table DRIVER_FLEET connects them bout and consist of driverID and fleetID.</p>

<p>Here is the example, from class Driver, that represents how my connection looks like.</p>

<pre><code>@ManyToMany(fetch = FetchType.LAZY, cascade=CascadeType.PERSIST)  
    @JoinTable(name="DRIVER_FLEET", 
                        joinColumns= { @JoinColumn(name="driverID")}, 
                        inverseJoinColumns={@JoinColumn(name="fleetID")}) 
        private List&lt;Fleet&gt; fleet = new ArrayList&lt;Fleet&gt;(); 
    public List&lt;Fleet&gt; getFleet() {
        return fleet;
    }
    public void setFleet(List&lt;Fleet&gt; fleet) {
        this.fleet = fleet;
    }
</code></pre>

<p>Here is class Fleet:</p>

<pre><code>@ManyToMany(mappedBy = "Driver")
    public Set&lt;Driver&gt; getDriver() {
        return getDriver();
    }
</code></pre>

<p>Now when I save Driver and Fleet into database using hibernate save(), I have this result in console:</p>

<pre><code>Hibernate: select driver0_.driverID as driverID1_2_, driver0_.commision as commisio2_2_, driver0_.dateOfBirth as dateOfBi3_2_, driver0_.driverDriveRateAmount as driverDr4_2_, driver0_.driverDriveRateCurrency as driverDr5_2_, driver0_.driverNumber as driverNu6_2_, driver0_.driverPayRateAmount as driverPa7_2_, driver0_.driverPayRateCurrency as driverPa8_2_, driver0_.driverPerOrderAmount as driverPe9_2_, driver0_.driverPerOrderCurrency as driverP10_2_, driver0_.firstName as firstNa11_2_, driver0_.gender as gender12_2_, driver0_.lastName as lastNam13_2_, driver0_.middleInitials as middleI14_2_ from Driver driver0_
Hibernate: select fleet0_.driverID as driverID1_2_0_, fleet0_.fleetID as fleetID2_0_0_, fleet1_.fleetID as fleetID1_3_1_, fleet1_.fleetName as fleetNam2_3_1_ from DRIVER_FLEET fleet0_ inner join Fleet fleet1_ on fleet0_.fleetID=fleet1_.fleetID where fleet0_.driverID=?
Hibernate: select fleet0_.driverID as driverID1_2_0_, fleet0_.fleetID as fleetID2_0_0_, fleet1_.fleetID as fleetID1_3_1_, fleet1_.fleetName as fleetNam2_3_1_ from DRIVER_FLEET fleet0_ inner join Fleet fleet1_ on fleet0_.fleetID=fleet1_.fleetID where fleet0_.driverID=?
Hibernate: select fleet0_.driverID as driverID1_2_0_, fleet0_.fleetID as fleetID2_0_0_, fleet1_.fleetID as fleetID1_3_1_, fleet1_.fleetName as fleetNam2_3_1_ from DRIVER_FLEET fleet0_ inner join Fleet fleet1_ on fleet0_.fleetID=fleet1_.fleetID where fleet0_.driverID=?
Hibernate: select fleet0_.driverID as driverID1_2_0_, fleet0_.fleetID as fleetID2_0_0_, fleet1_.fleetID as fleetID1_3_1_, fleet1_.fleetName as fleetNam2_3_1_ from DRIVER_FLEET fleet0_ inner join Fleet fleet1_ on fleet0_.fleetID=fleet1_.fleetID where fleet0_.driverID=?
Hibernate: select fleet0_.driverID as driverID1_2_0_, fleet0_.fleetID as fleetID2_0_0_, fleet1_.fleetID as fleetID1_3_1_, fleet1_.fleetName as fleetNam2_3_1_ from DRIVER_FLEET fleet0_ inner join Fleet fleet1_ on fleet0_.fleetID=fleet1_.fleetID where fleet0_.driverID=?
Hibernate: select driver0_.driverID as driverID1_2_, driver0_.commision as commisio2_2_, driver0_.dateOfBirth as dateOfBi3_2_, driver0_.driverDriveRateAmount as driverDr4_2_, driver0_.driverDriveRateCurrency as driverDr5_2_, driver0_.driverNumber as driverNu6_2_, driver0_.driverPayRateAmount as driverPa7_2_, driver0_.driverPayRateCurrency as driverPa8_2_, driver0_.driverPerOrderAmount as driverPe9_2_, driver0_.driverPerOrderCurrency as driverP10_2_, driver0_.firstName as firstNa11_2_, driver0_.gender as gender12_2_, driver0_.lastName as lastNam13_2_, driver0_.middleInitials as middleI14_2_ from Driver driver0_
Hibernate: select fleet0_.driverID as driverID1_2_0_, fleet0_.fleetID as fleetID2_0_0_, fleet1_.fleetID as fleetID1_3_1_, fleet1_.fleetName as fleetNam2_3_1_ from DRIVER_FLEET fleet0_ inner join Fleet fleet1_ on fleet0_.fleetID=fleet1_.fleetID where fleet0_.driverID=?
Hibernate: select fleet0_.driverID as driverID1_2_0_, fleet0_.fleetID as fleetID2_0_0_, fleet1_.fleetID as fleetID1_3_1_, fleet1_.fleetName as fleetNam2_3_1_ from DRIVER_FLEET fleet0_ inner join Fleet fleet1_ on fleet0_.fleetID=fleet1_.fleetID where fleet0_.driverID=?
Hibernate: select fleet0_.driverID as driverID1_2_0_, fleet0_.fleetID as fleetID2_0_0_, fleet1_.fleetID as fleetID1_3_1_, fleet1_.fleetName as fleetNam2_3_1_ from DRIVER_FLEET fleet0_ inner join Fleet fleet1_ on fleet0_.fleetID=fleet1_.fleetID where fleet0_.driverID=?
Hibernate: select fleet0_.driverID as driverID1_2_0_, fleet0_.fleetID as fleetID2_0_0_, fleet1_.fleetID as fleetID1_3_1_, fleet1_.fleetName as fleetNam2_3_1_ from DRIVER_FLEET fleet0_ inner join Fleet fleet1_ on fleet0_.fleetID=fleet1_.fleetID where fleet0_.driverID=?
Hibernate: select fleet0_.driverID as driverID1_2_0_, fleet0_.fleetID as fleetID2_0_0_, fleet1_.fleetID as fleetID1_3_1_, fleet1_.fleetName as fleetNam2_3_1_ from DRIVER_FLEET fleet0_ inner join Fleet fleet1_ on fleet0_.fleetID=fleet1_.fleetID where fleet0_.driverID=?
Hibernate: insert into Driver (commision, dateOfBirth, driverDriveRateAmount, driverDriveRateCurrency, driverNumber, driverPayRateAmount, driverPayRateCurrency, driverPerOrderAmount, driverPerOrderCurrency, firstName, gender, lastName, middleInitials) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into DRIVER_LICENSE (expirationDate, stateIssued, driverID, licenseID) values (?, ?, ?, ?)
Hibernate: insert into DRIVER_FLEET (driverID, fleetID) values (?, ?)
</code></pre>

<p>From this console log you can see that I have two many these rows</p>

<pre><code>Hibernate: select fleet0_.driverID as driverID1_2_0_, fleet0_.fleetID as fleetID2_0_0_, fleet1_.fleetID as fleetID1_3_1_, fleet1_.fleetName as fleetNam2_3_1_ from DRIVER_FLEET fleet0_ inner join Fleet fleet1_ on fleet0_.fleetID=fleet1_.fleetID where fleet0_.driverID=?
</code></pre>

<p>The problem is, if I have more rows in table DRIVER_FLEET, then I have more rows of those select queries. Is there some possibility that I have made something wrong in ManyToMany connection? Can my performance be better? </p>