java - More than one "one to many" association using Detached Criteria (XML Based Hibernate Configuration) -
i trying join 3 tables using detached criteria class of hibernate.
i have 3 tables student,student_correspond,student_courses
primary keys of tables
**table names** **primary keys** student inqry_id student_correspond student_crsp_id student_courses course_cd
select *from db01.student inner join db01.student_correspond on db01.student.inqry_id =db01.student_correspond.inqry_id inner join db01.student_courses on db01.student_courses.course_cd=db01.student.course_cd
actual db results above query 250 in database.
i want achieve above query using detached criteria.
in studentdo.hbm.xml,i have added following code when ran application it's not displaying results.i.e
the results count zero.
studentdo.hbm.xml
<set name="studentids" lazy="true" inverse="true" cascade="none" sort="unsorted" batch-size="10"> <key><column name="inqry_id" /></key> <one-to-many class="com.test.studentcorrespondencedo"/> </set> <set name="coursecodes" lazy="true" inverse="true" cascade="none" sort="unsorted" batch-size="10"> <key><column name="course_cd"/></key> <one-to-many class="com.test.studentcoursesdo"/> </set>
i have added respected setter , getter methods in studentdo.java file.
my application main file looks follows
detachedcriteria detachedcriteria =detachedcriteria.forclass(studentdo.class); detachedcriteria.createcriteria("studentids","stuids",criteria.inner_join); detachedcriteria.createcriteria("coursecodes","coursecds",criteria.inner_join); list l = gethibernatetemplate().findbycriteria(detachedcriteria); system.out.println(l.size());
the result zero.
but when have coded (only 2 tables joining ) ---------------------------------------------------------------------- select *from db01.student inner join db01.student_correspond on db01.student.inqry_id =db01.student_correspond.inqry_id
actual db results count 10.
i want achieve above query using detached criteria.
studentdo.hbm.xml
<set name="studentids" lazy="true" inverse="true" cascade="none" sort="unsorted" batch-size="10"> <key><column name="inqry_id" /></key> <one-to-many class="com.test.studentcorrespondencedo"/> </set>
i have added respected setter , getter methods in studentdo.java file. when ran application it's displaying correct results. 10
my application main file looks follows 2 tables
detachedcriteria detachedcriteria =detachedcriteria.forclass(studentdo.class); detachedcriteria.createcriteria("studentids","stuids",criteria.inner_join); list l = gethibernatetemplate().findbycriteria(detachedcriteria); system.out.println(l.size());
as,i mentioned joins of 2 tables working fine.but 3 tables joining not working. please 1 provide solution problem.it great helpful side.
thanks lot.
Comments
Post a Comment