Unnecessary "left outer join". Probably this "left outer join" can be eliminated. OneToOne when optional=true and LAZY

Description

Hi

Relation between Person and Office is: 1 to {0 or 1}

There a 3 classes (sources attached):

  • PersonPk

  • Person

  • Office

SCENARIO
-------- final Office office = em.find(Office.class, new PersonPk("adam", "woz"));
System.out.println(office.getPerson().getZodiac());

I second line the following SQL is generated:
select
person0_.first_name as first1_22_1_,
person0_.last_name as last2_22_1_,
person0_.zodiac as zodiac22_1_,
office1_.first_name as first1_23_0_,
office1_.last_name as last2_23_0_,
office1_.address as address23_0_
from
PERSON person0_
left outer join
OFFICE office1_
on person0_.first_name=office1_.first_name
and person0_.last_name=office1_.last_name
where
person0_.first_name=?
and person0_.last_name=?

But we already know all columns for OFFICE so there is need to loaded them once again. In other words this SQL can be reduced to such SQL:

select
person0_.first_name as first1_22_1_,
person0_.last_name as last2_22_1_,
person0_.zodiac as zodiac22_1_,
from
PERSON person0_
where
person0_.first_name=?
and person0_.last_name=?

Kind regards,
Adam Woźniak / Poland

Environment

n/a

Assignee

Unassigned

Reporter

Adam Wozniak

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major