-->
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: Object plus Child Count in One Query?
PostPosted: Sun Oct 02, 2005 12:50 am 
Beginner
Beginner

Joined: Mon Sep 08, 2003 10:21 pm
Posts: 40
Location: Honolulu, HI
Hello,

Is there a way to write a HQL or Criteria query to select both the parent and the count of child objects at once? We're aware of the filter to get the child count without initializing the whole collection, but that's N*2 queries.

Hopefully there's a way to do it all at once.

Thanks very much!
Seth

Hibernate version: 2.1.8

Mapping documents:
Code:
<hibernate-mapping>

    <class name="org.example.tree.Person" table="person">

        <id name="id" unsaved-value="null" type="long">
            <generator class="native"/>
        </id>

        <property name="firstName" column="first_name"/>
        <property name="lastName" column="last_name" />
       
        <set lazy="true" batch-size="25" name="children" inverse="true">
          <key column="parent_id" />
          <one-to-many class="org.example.tree.Person" />
        </set>
       
        <many-to-one name="parent" column="parent_id" />

    </class>

</hibernate-mapping>


Name and version of the database you are using: MySQL 4.1
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 25, 2005 8:19 am 
Beginner
Beginner

Joined: Mon Sep 08, 2003 10:21 pm
Posts: 40
Location: Honolulu, HI
Just a reply to myself, you can do this using a formula. Formula's understand properties from the enclosing object. Very cool.


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.