java - Hibernate @Fetch(Join) isn't being applied instead of separate SELECTs -
i have domain
entity @manytoone
uni-directional relation country
entity i'd eagerly loaded join instead of separate selects. thought using @fetch
.
@entity @table public class domain { @id @genericgenerator(name = "generator", strategy = "increment") @generatedvalue(generator = "generator") @column(name = "domain_id") private long domainid; @fetch(fetchmode.join) @manytoone(optional = false, fetch = fetchtype.eager) private country country; ... }
i'm using hql
query these entities.
but hibernate doesn't apply fetching strategy. i've tried @onetoone
(which doesn't change in design), doesn't work. here's sample sql output
hibernate: select domain0_.domain_id domain1_2_, domain0_.country country2_, domain0_.name name2_, domain0_.type type2_ domain domain0_ order domain0_.name limit ? hibernate: select country0_.country_id country1_1_0_, country0_.code code1_0_, country0_.currency currency1_0_, country0_.name name1_0_ country country0_ country0_.country_id=? hibernate: select country0_.country_id country1_1_0_, country0_.code code1_0_, country0_.currency currency1_0_, country0_.name name1_0_ country country0_ country0_.country_id=? hibernate: select country0_.country_id country1_1_0_, country0_.code code1_0_, country0_.currency currency1_0_, country0_.name name1_0_ country country0_ country0_.country_id=? hibernate: select country0_.country_id country1_1_0_, country0_.code code1_0_, country0_.currency currency1_0_, country0_.name name1_0_ country country0_ country0_.country_id=? hibernate: select country0_.country_id country1_1_0_, country0_.code code1_0_, country0_.currency currency1_0_, country0_.name name1_0_ country country0_ country0_.country_id=?
i'm assuming preventing being applied. that?
i querying domain
entities like
from domain domain domain.type = :type
and causing hibernate query country
entity individually each domain
returned.
based on tom anderson's comment , answer here, made change in hql to
from domain domain join fetch domain.country domain.type = :type
this causes hibernate use 1 big query join in retrieve domain
, country
together, instead of 1 query domain
entities , select
retrieve country
each of those.
with criteria
, seems isn't necessary. when use hql need specify join fetch
.
Comments
Post a Comment