Sunday, 15 February 2015

hql - how to use fetch in Hibernate Query Language -



hql - how to use fetch in Hibernate Query Language -

this not techincal problem, syntax correction not getting.

i have hibernate 3.6 , have mapped model classes in xml files. default type mentioned in xml files these classes brought lazily. since hardcoded, cannot alter behaviour.

the model trying bring looks this.

class { private int id; private b b; private c c; }

the classes b , c needs loaded eagerly in case.

so wrote query this.

from a.class.getname() a.id = :id;

in query, set fetch keyword. below 1 throws errors:

from a.class.getname fetch a.id = :id;

in examples on internet, doing joins on query , getting values this:

from cat cat inner bring together fetch cat.mate left bring together fetch cat.kittens

however, in case, joins done internally in xml files. don't have joins in query. set "fetch" keyword state initiate linked classes (b , c) @ same time non-lazily.

note:

i cannot utilize criteria api because don't want add together additional jars in project.

the syntax is

select a left bring together fetch a.b left bring together fetch a.c a.id = :id

relevant part of the documentation:

a "fetch" bring together allows associations or collections of values initialized along parent objects using single select. particularly useful in case of collection. overrides outer bring together , lazy declarations of mapping file associations , collections. see section 20.1, “fetching strategies” more information.

from cat cat inner bring together fetch cat.mate left bring together fetch cat.kittens

hibernate hql

No comments:

Post a Comment