-->
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.  [ 6 posts ] 
Author Message
 Post subject: how can I order by this
PostPosted: Tue Apr 27, 2004 8:50 am 
Newbie

Joined: Tue Apr 27, 2004 2:36 am
Posts: 12
I create a HQL, but it doesn't works why?

Code:
Select count(record.book) from record group by record.book order by count(record.book)



but if I use the SQL, it can be work i think

Code:
select count(record.bookid) as c from record group by record.bookid order by c;



Why HQL doesn't works???????
or the HQL can't support this.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 27, 2004 9:22 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
1- give sql generated by your hql query
2- try
Code:
select record, count( elements(record.books) )
from Record record group by count( elements(record.books)


Top
 Profile  
 
 Post subject: my Mapping File
PostPosted: Tue Apr 27, 2004 9:37 am 
Newbie

Joined: Tue Apr 27, 2004 2:36 am
Posts: 12
Visit
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
    PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

    <class name="com.risinginfo.WebObserver.PersistentClass.Visit" table="Visit">

        <id name="visitID" type="long" unsaved-value="null" >
            <column name="VisitID" not-null="true"/>
            <generator class="increment"/>
        </id>

        <many-to-one name="visitUser" cascade="none" class="com.risinginfo.WebObserver.PersistentClass.User">
            <column name="UserID" sql-type="varchar(20)"/>
        </many-to-one>
        <many-to-one name="visitWeb" class="com.risinginfo.WebObserver.PersistentClass.Web"
            column="WebID" cascade="none"/>
        <property name="visitTime">
            <column name="VisitTime"/>
        </property>

    </class>

</hibernate-mapping>


Web
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
    PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

    <class name="com.risinginfo.WebObserver.PersistentClass.Web" table="Web">

        <id name="webID" type="long" unsaved-value="null" >
            <column name="WebID" not-null="true"/>
            <generator class="increment"/>
        </id>

        <property name="domainName" type="java.lang.String">
            <column name="webDN" not-null="true"/>
        </property>

        <property name="webName" >
            <column name="WebName"  sql-type="VARBINARY(255)" not-null="false"/>
        </property>

    </class>

</hibernate-mapping>


now I try the HQL like this
Code:
select Visit.visitWeb, count(elements(Visit.visitWeb))
from Visit Visit
group by count(elements(Visit.visitWeb))


but get error
Code:
net.sf.hibernate.QueryException: could not resolve property: elements of: com.risinginfo.WebObserver.PersistentClass.Web [select Visit.visitWeb, count(elements(Visit.visitWeb))

from com.risinginfo.WebObserver.PersistentClass.Visit Visit

group by count(elements(Visit.visitWeb))]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 27, 2004 11:33 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
the elements function does not apply to a single valued association, of course.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 27, 2004 11:45 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
excuse i have misunderstood the domain model... :(


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 27, 2004 9:23 pm 
Newbie

Joined: Tue Apr 27, 2004 2:36 am
Posts: 12
Oh gavin, could you tell me how can I order by count(*)


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