Я использую open JDK 11, JPA 2.1 и Hibernate Core 5.4.0.Final. У меня есть сущность Ave
, которая имеет много дочерних ассоциаций, среди которых Bid
и Buyer
. Количество элементов:
1 Ave : Many Bid
1 Ave : Many Buyer
Это фрагмент исходного кода объекта Ave
:
@Entity
@Table(name = "ave")
@Access(AccessType.FIELD)
public class Ave implements Serializable, SearchableEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "id", updatable = false, nullable = false)
private int id;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.MERGE, targetEntity = Buyer.class)
@JoinColumn(name = "ave_id")
@Fetch(value = FetchMode.JOIN)
private Set<Buyer> allPotentialBuyers = new LinkedHashSet<>();
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, targetEntity = Bid.class)
@JoinColumn(name = "ave_id")
@Fetch(value = FetchMode.JOIN)
private Set<Bid> bids = new HashSet<>();
// ... more code here ....
}
Когда я выполняю запрос JPA
Query query2 = this.em.createQuery(" select ave from Ave ave where ave.id =16 ");
query2.getResultList();
hibernate выполняет 3 (три) SQL запроса, хотя я не получаю sh, чтобы получить ни Bid
, ни Buyer
:
1.) FIRST Запрос - извлечение Ave
сущностей - ОК:
04:34:15,717 INFO [stdout] (default task-2) Hibernate: select ave0_.id as id1_0_, ave0_.angebotType as angebotT2_0_, ave0_.bidStep as bidStep3_0_, ave0_.bidwinner_id as bidwinne7_0_, ave0_.endDate as endDate4_0_, ave0_.home_id as home_id8_0_, ave0_.user_id as user_id5_0_, ave0_.startDate as startDat6_0_, ave0_.vertragsErrichter_id as vertrags9_0_ from ave ave0_ where ave0_.id=16
2.) Запрос Secodn - извлечение связанных Bid
с - почему? Я НЕ ХОЧУ!:
04:34:15,928 INFO [stdout] (default task-2) Hibernate: select bids0_.ave_id as ave_id3_4_0_, bids0_.id as id1_4_0_, bids0_.id as id1_4_1_, bids0_.abgabeDatum as abgabeDa2_4_1_, bids0_.ave_id as ave_id3_4_1_, bids0_.bidmaker_id as bidmaker6_4_1_, bids0_.bidPrice as bidPrice4_4_1_, bids0_.status as status5_4_1_, bids0_.vtgerrichter_id as vtgerric7_4_1_ from bid bids0_ where bids0_.ave_id=?
3.) Третий запрос - выбирает связанные Buyer
s - почему? Я НЕ ХОЧУ:
04:34:16,082 INFO [stdout] (default task-2) Hibernate: select allpotenti0_.ave_id as ave_id2_5_0_, allpotenti0_.id as id1_5_0_, allpotenti0_.id as id1_5_1_, allpotenti0_.ave_id as ave_id2_5_1_, allpotenti0_.contact_id as contact_3_5_1_, allpotenti0_.idx as idx4_5_1_, allpotenti0_.main_buyer_id as main_buy5_5_1_ from buyer allpotenti0_ where allpotenti0_.ave_id=?