-->
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.  [ 3 posts ] 
Author Message
 Post subject: Getting Count From Child Items
PostPosted: Thu Jun 15, 2006 6:59 am 
Newbie

Joined: Sat Jun 10, 2006 10:24 am
Posts: 16
Hi People,

I have this Query:

IQuery Q = Session.CreateQuery("from Linked.Core.Domain.UserEntity as ue order by ue.Links.Count asc");
Q.SetMaxResults(5);
return Q.List<UserEntity>();

When executed the system simply says:

expecting 'elements' or 'indices' after Count [from Linked.Core.Domain.UserEntity as ue order by ue.Links.Count asc]

What am I missing?

Thanks Heaps!
-Alex

Hibernate version:N-1.2.0.Alpha1


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 7:56 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Try .size instead of .Count.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 8:30 pm 
Newbie

Joined: Sat Jun 10, 2006 10:24 am
Posts: 16
Hi Sergey,

I tired that so my query became:

IQuery Q = Session.CreateQuery("from Linked.Core.Domain.UserEntity as ue order by ue.Links.size asc");
Q.SetMaxResults(5);
return Q.List<UserEntity>();

but now the error is:

{"#HY000Invalid use of group function"}

and the SQL it generated is:

{select userentity0_.Id as Id, userentity0_.Name as Name4_, userentity0_.Email as Email4_, userentity0_.CreatedDate as CreatedD5_4_, userentity0_.IsAdmin as IsAdmin4_, userentity0_.TimeStamp as TimeStamp4_, userentity0_.Password as Password4_ from database.user userentity0_ order by count(*) asc}

Hmmm it seems like it isn't generating the join between the objects any idea how to fix it what i have done wrong?

Thanks heaps for your help so far!
-Alex


Here is my mapping:

Code:
<hibernate-mapping
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns='urn:nhibernate-mapping-2.0'>
   <meta
       attribute='scope-class'>public partial</meta>
   <class
       name='Linked.Core.Domain.CategoryEntity, Linked.Core'
       lazy='true'
       table='category'>

      <meta
          attribute='extends'>DomainEntity&lt;CategoryEntity, int&gt;</meta>
      <cache usage='read-write' />
      <id
          name='Id'
          column='Id'
          type='Int32'
          unsaved-value='0'>
         <meta
             attribute='gen-property'>false</meta>
         <generator
             class='native' />
      </id>
      <property
          name='Name'
          type='String'
          column='Name'
          length='150'
          not-null='true' />
      <property
          name='Timestamp'
          type='DateTime'
          column='Timestamp' />
      <bag
          name='Links'
          cascade='all'
          inverse='true'>
         <key
             column='CategoryId' />
         <one-to-many
             class='Linked.Core.Domain.LinkEntity, Linked.Core' />
      </bag>
      <bag
          name='ChildCategories'
          lazy='true'>
         <key
             column='ParentId' />
         <one-to-many
             class='Linked.Core.Domain.CategoryEntity, Linked.Core' />
      </bag>
      <many-to-one
          name='ParentCategory'
          class='Linked.Core.Domain.CategoryEntity, Linked.Core'
          column='ParentId'
          foreign-key='Id' />
   </class>
   <class
       name='Linked.Core.Domain.LinkEntity, Linked.Core'
       lazy='true'
       table='link'>
      <meta
          attribute='extends'>DomainEntity&lt;LinkEntity, int&gt;</meta>
      <cache usage='read-write' />
      <id
          name='Id'
          column='Id'
          type='Int32'
          unsaved-value='0'>
         <meta
             attribute='gen-property'>False</meta>
         <generator
             class='native' />
      </id>
      <property
          name='Href'
          type='String'
          column='Href'
          length='200'
          not-null='true' />
      <property
          name='Description'
          type='String'
          column='Description'
          length='200'
          not-null='true' />
      <property
          name='Name'
          type='String'
          column='Name'
          length='200'
          not-null='true' />
      <property
          name='Visits'
          type='Int32'
          column='Visits'
          not-null='true' />
      <property
          name='AddedDate'
          type='DateTime'
          column='AddedDate'
          not-null='true' />
      <property
          name='IsPublic'
          type='Byte'
          column='IsPublic'
          not-null='true' />
      <property
          name='Timestamp'
          type='DateTime'
          column='TimeStamp' />
      <bag
          name='Ratings'
          lazy='true'>
         <key
             column='LinkId' />
         <one-to-many
             class='Linked.Core.Domain.RatingEntity, Linked.Core' />
      </bag>
      <many-to-one
          name='User'
          class='Linked.Core.Domain.UserEntity, Linked.Core'
          column='UserId'
          foreign-key='Id' />
      <many-to-one
          name='Category'
          class='Linked.Core.Domain.CategoryEntity, Linked.Core'
          column='CategoryId'
          foreign-key='Id' />

      <idbag
         name='MyUser'
         table='mylink'
         lazy ='true'
         cascade='all'
         inverse='true'>

         <collection-id column="Id" type="Int32">
            <generator class="increment" />
         </collection-id>

         <key column='LinkId' />
         <many-to-many
             class='Linked.Core.Domain.UserEntity, Linked.Core'
             column='UserId'
              />
      </idbag>

   </class>
   <class
       name='Linked.Core.Domain.RatingEntity, Linked.Core'
       lazy='true'
       table='rating'>
      <meta
          attribute='extends'>DomainEntity&lt;RatingEntity, int&gt;</meta>
      <cache usage='read-write' />
      <id
          name='Id'
          column='Id'
          type='Int32'
          unsaved-value='0'>
         <meta
             attribute='gen-property'>False</meta>
         <generator
             class='native' />
      </id>
      <property
          name='Value'
          type='Int32'
          column='Value'
          not-null='true' />
      <many-to-one
          name='User'
          class='Linked.Core.Domain.UserEntity, Linked.Core'
          column='UserId'
          foreign-key='Id' />
      <many-to-one
          name='Link'
          class='Linked.Core.Domain.LinkEntity, Linked.Core'
          column='LinkId'
          foreign-key='Id' />
   </class>
   <class
       name='Linked.Core.Domain.UserEntity, Linked.Core'
       lazy='true'
       table='user'>
      <meta
          attribute='extends'>DomainEntity&lt;UserEntity, int&gt;</meta>
      <cache usage='read-write' />
      <id
          name='Id'
          column='Id'
          type='Int32'
          unsaved-value='0'>
         <meta
             attribute='gen-property'>False</meta>
         <generator
             class='native' />
      </id>
      <property
          name='Name'
          type='String'
          column='Name'
          length='100'
          not-null='true' />
      <property
          name='Email'
          type='String'
          column='Email'
          length='100'
          not-null='true' />
      <property
          name='Password'
          type='String'
          column='Password'
          length='100'
          not-null='true' />
      <property
          name='CreatedDate'
          type='DateTime'
          column='CreatedDate'
          not-null='true' />
      <property
          name='IsAdmin'
          type='Byte'
          column='IsAdmin'
          not-null='true' />
      <property
          name='Timestamp'
          type='DateTime'
          column='TimeStamp' />
      <bag
          name='Links'
          lazy='true'>
         <key
             column='UserId' />
         <one-to-many
             class='Linked.Core.Domain.LinkEntity, Linked.Core' />
      </bag>
      <bag
          name='Ratings'
          lazy='true'>
         <key
             column='UserId' />
         <one-to-many
             class='Linked.Core.Domain.RatingEntity, Linked.Core' />
      </bag>
      <idbag
          name='MyLinks'
          table='mylink'
          lazy ='true'
          cascade='all'
          inverse='false'
          >

         <collection-id column="Id" type="Int32">
            <generator class="increment" />
         </collection-id>

         <key column='UserId' />
         <many-to-many
             class='Linked.Core.Domain.LinkEntity, Linked.Core'
             column='LinkId'
              />
      </idbag>
   </class>
</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.