I have two entities, Item
and Data
, and a DTO class ItemData
. ItemData
consists of Item
and Data
and has no JPA mapping. To retreive a list of populated ItemDatas, I use a constructor expression in JPQL:
select new my.package.ItemData(i, d)
from Item i, Data d
where i.id = d.itemId
This is what Hibernate is doing: Instead of fetching both the data of Item
and Data
, it gets their IDs first and the data afterwards in n separate select statements. Is there a way to change this behaviour?
Hibernate:
select
item0_.id as col_0_0_,
data1_.id as col_1_0_
from
ITEM item0_,
DATA data1_
Hibernate:
select
item0_.no as no1_0_,
item0_.description as description1_0_,
item0_.organic as bio1_0_,
item0_.gluten as gluten1_0_,
item0_.laktose as laktose1_0_
from
ITEM item0_
where
item0_.id=?
Hibernate:
select
data0_.amount as amount1_3_0_,
data0_.avg as avg3_0_,
data0_.total as total3_0_
from
DATA data0_
where
data0_.id=?
Hibernate:
select
item0_.no as no1_0_,
item0_.description as description1_0_,
item0_.organic as bio1_0_,
item0_.gluten as gluten1_0_,
item0_.laktose as laktose1_0_
from
ITEM item0_
where
item0_.id=?
Hibernate:
select
data0_.amount as amount1_3_0_,
data0_.avg as avg3_0_,
data0_.total as total3_0_
from
DATA data0_
where
data0_.id=?
...and so on...