Hibernate 4.3.0.Final: select on multiple table -
i'm using hibrnate core 4.3.0.
i have 2 table; table related m:n table b
i have structure:
table a:
- id: primary key
- name: name of element
- state: state of element
table b:
- *id_source*: fk table a
- *id_target*: fk table a
- *relation_name*: name of relation type
in table b primary key composite 1 composed id_source , id_target.
now have been able in creating classes correctly mapped; i'ld love make following query:
select id, name, state table_a this1, table_b src1_ src1_.id_source=4018 , src1_.id_target=this1.id
now know may use hql and/or native sql in order create such kind of query, i'ld love use hibernate criteria or better detachedcriteria
is possible create such query using detachedcriteria?
thank you
angelo
i guess found way using setfetchmode; wrote detachedcriteria (note: mapped relationship fields fetch=fetchtype.lazy
):
detachedcriteria dc = detachedcriteria.forclass(b.class); dc.setfetchmode("tgta", fetchmode.join); dc.add(property.forname("srca.id").eq(4018l));
this has been transformed hibernate in following query:
select b.id_source, b.id_target, b.relation_name, a.id, a.name, a.state b b inner join a on b.id_target=a.id_entity b.id_source=?
now wondering performances when execute kind of query....is right way it?
thank you
angelo
Comments
Post a Comment