java - Hibernate asks for collections using multiple selects instead of one, how to change it? -


i using hibernate 3, oracle , java. have employee class , mapping:

<set name="meetings" table="employee_meeting" inverse="false" lazy="false" fetch="select" cascade="all" >     <key column="employee_id" />     <composite-element class="employeemeeting">         <parent name="employee" />         <many-to-one name="meeting" column="meeting_id" not-null="true" cascade="all"             class="meeting" />         <property name="opinion" column="opinion" />     </composite-element> </set>  

there on 100 meetings , hibernate using below selects on 100 of times: hibernate: select this_.employee_id employee1_0_0_, this_.firstname firstname0_0_, this_.lastname lastname0_0_ employee this_ this_.employee_id=? hibernate: select meetings0_.employee_id employee1_0_, meetings0_.meeting_id meeting2_0_, meetings0_.opinion opinion0_ employee_meeting meetings0_ meetings0_.employee_id=?

now there query

    list emps = session.createcriteria(employee.class)     .add( restrictions.eq("age", new long(25)) ).list(); 

that query returns 10 employees age 25 , performs on 100 selects visible in logs.

i tried change fetch="select" fetch="join" there cartesian effect, query return plenty of same employees.. despite there 1 query database visible in log file, wrong solution..

how change thate hibernate retrieve meetings collection using little database selects possible still return 10 employees?

judicious use of distinct can deal duplicates caused cartesian effect, eg:

select distinct employee... 

but more can deal selecting set rather list, , making sure have equals() , hashcode() implementation on employee class - set ensure single instance each employee...


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -