When using bytecode enhancement with a ManyToOne relation and a Lazy Group, 2 queries are executed instead of one.
Code omitted for brevity
{code:java} @Entity public class BugLazyGrp {
@LazyGroup(value = "bugLazyGrp_refmany1") @LazyToOne(value = LazyToOneOption.NO_PROXY) @ManyToOne(fetch=FetchType.LAZY, optional = false) @JoinColumn(name = "REF_MANY_1ID") private RefMany1 refMany1; @LazyGroup(value = "bugLazyGrp_refmany2") @LazyToOne(value = LazyToOneOption.NO_PROXY) @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name = "REF_MANY_2ID") private RefMany2 refMany2; @LazyGroup(value = "bugLazyGrp_refone") @LazyToOne(value = LazyToOneOption.NO_PROXY) @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "bugLazyGrp") private RefOne refOne;
{code}
{code:java} BugLazyGrp element = em.find(BugLazyGrp.class, 1L);
// one query for this one -> ok // case 1 RefOne refOne = element.getRefOne(); // two queries -> KO // case 2 RefMany1 refMany1 = element.getRefMany1(); {code}
Case 1 is fine, sql generated is : * select refone0_.ref_one_id as ref_one_1_3_0_, refone0_.label as label2_3_0_ from ref_one refone0_ where refone0_.bug_lazy_grp_id=?
*Case 2 generate 2 queries instead of 1* * select buglazygrp_.ref_many_1id as ref_many3_0_ from bug_lazy_grp buglazygrp_ where buglazygrp_.bug_lazy_grp_id=? * select refmany1x0_.ref_many_1id as ref_many1_1_0_, refmany1x0_.description as descript2_1_0_ from ref_many_1 refmany1x0_ where refmany1x0_.ref_many_1id=?
Example code provided with manual test case |
|