I am trying to improve application performance using Hibernate, which performs too many SQL calls in a database. I think data sampling can be grouped together to reduce the number of calls and improve performance, but I'm losing a bit here. I looked at the Hibernate documentation on subqueries and batch fetching that helps, but I don't think it completely fixes the problem.
In the example below, I need to get detailed information about the list of soldiers that make up the troops and display them on a web page.
@Entity
public class Troop {
@OneToMany(mappedBy="troop")
public List<Soldier> getSoldiers() {
...
}
It is easy to set a sampling strategy for a subquery that is batch or desired to retrieve all the soldiers of this unit without too many SQL statements.
@Entity
public class Soldier {
@Id
String soldierId
String firstName;
String lastName;
@OneToMany(mappedBy="address")
public List<Soldier> getAddress() {
...
@OneToMany(mappedBy="combatHistory")
public List<Soldier> getCombatHistory() {
...
@OneToMany(mappedBy="medicalHistory")
public List<Soldier> getMedicalHistory() {
...
}
, . . 3 , 1000 , 3- SQL!
, ? soldierIds, , ?
,
from Address as a where a.soldierId in (...)
from CombatHistory as a where a.soldierId in (...)
from MedicalHistory as a where a.soldierId in (...)
Address, CombatHistory .. , SQL . ( 3), (3 1000).
, . , , , Hibernate .
HibernateException: cannot simultaneously fetch multiple bags