-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Criteria generates many select statements
PostPosted: Wed Dec 10, 2003 9:57 am 
Newbie

Joined: Wed Dec 10, 2003 4:03 am
Posts: 1
Hello,

I have the associations as follows:
Code:
   <class name="eg.FModello">
      <id column="ID" name="id" type="java.lang.Long">
         <generator class="sequence"/>
      </id>
      ...
      <property name="fiscal" type="java.lang.String" column="CDFISCAL" length="50"/>
     
      <set name="terreni" inverse="false">
    <key column="IDMODELLO"/>
    <one-to-many class="eg.FTerreni"/>
      </set>
     
      <one-to-one name="qA" class="eg.QA" cascade="save-update" outer-join="false" constrained="false" property-ref="modello"/>
      <one-to-one name="qB" class="eg.QB" cascade="save-update" outer-join="false" constrained="false" property-ref="modello"/>
      <one-to-one name="qC" class="eg.QC" cascade="save-update" outer-join="false" constrained="false" property-ref="modello"/>
   </class>
   
   <class name="eg.FTerreni">
      <id column="ID" name="id" type="java.lang.Long">
         <generator class="sequence"/>
      </id>
      <property column="PRTERRENI" length="22" name="prterreni" not-null="true" type="java.lang.Long"/>
      ....
      <many-to-one name="modello" class="eg.FModello" column="IDMODELLO" outer-join="false" cascade="save-update" />
   </class>
   
   <class name="eg.QA">
      <id column="ID" name="id" type="java.lang.Long">
         <generator class="sequence"/>
      </id>
      ...
      <many-to-one name="modello" class="eg.FModello" column="IDMODELLO" outer-join="false" not-null="true" />
   </class>


mapping for QB, QC is the same <many-to-one> as in QA

When using criteria as follows

Code:
results = session.createCriteria(Ffamili.class)
       .add(Expression.between("prterreni", min, max))
       .createCriteria("modello")
      .add(Expression.eq("fiscal", "0205"))
       .list();


hibernate generates many select statements
Code:
...   
Hibernate: select ... from GE730.FTERRENI fterreni0_ where fterreni0_.IDMODELLO=?
Hibernate: select ... from GE730.QA where QA.IDMODELLO=?
Hibernate: select ... from GE730.QB where QB.IDMODELLO=?
Hibernate: select ... from GE730.QC where QC.IDMODELLO=?
...


is there any way to do such kind of criteria without doing all those select to parent class,
i've tried using .setFetchMode() but result is the same.
Is there a better way? missing something?

In passed few years i've used Torque, must say u have created a great lib.
The only thing that i-am missing much is not allowing to access foreign key as property directly (is there ANY way?)
this has a huge performance impact on systems that (for example) uses "lookup tables" (in my case they have > 60000 rows).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 10:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
i've tried using .setFetchMode() but result is the same.


eh? Perhaps you need to try this again.

Quote:
In passed few years i've used Torque, must say u have created a great lib.
The only thing that i-am missing much is not allowing to access foreign key as property directly (is there ANY way?)


Sure. Map a property with insert="false" update="false". But you don't need to do this since:

foo.getBar().getId()

does not initialize the proxy of the Bar.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.