-->
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.  [ 4 posts ] 
Author Message
 Post subject: trouble with query
PostPosted: Wed Feb 09, 2005 4:35 am 
Newbie

Joined: Wed Feb 09, 2005 4:27 am
Posts: 3
Hi there,

I am having trouble getting a HQL query to render properly to SQL.

The query is as follows:

from InternalMessage i where i.receiver = :user and hasBeenRead = false ORDER BY i.sender DESC , i.senderGroup DESC

This is because in my system, a message can come from a group of users, or from a single user.

The following SQL gets generated:

select internalme0_.id as id, internalme0_.senderuserid as senderus2_, internalme0_.sendergroupid as senderba3_, internalme0_.receiveruserid as receiver4_, internalme0_.receivergroupid as receiver5_, internalme0_.subject as subject, internalme0_.message as message, internalme0_.hasbeenread as hasbeenr8_, internalme0_.timesent as timesent, internalme0_.messagetype as message10_ from pixel_internalmessage internalme0_, pixel_user user1_, pixel_group group2_ where internalme0_.senderuserid=user1_.id AND internalme0_.sendergroupid=group2_.id and ((internalme0_.receiveruserid=1 )) order by user1_.username DESC , group2_.name DESC

Which returns no rows because of this SQL:

internalme0_.senderuserid=user1_.id AND internalme0_.sendergroupid=group2_.id

changing the query so that the above reads:

(internalme0_.senderuserid=user1_.id OR internalme0_.sendergroupid=group2_.id )

functions exactly like I want it too! (I tried it in the database. returns all the rows I need!)

full:

select internalme0_.id as id, internalme0_.senderuserid as senderus2_, internalme0_.sendergroupid as senderba3_, internalme0_.receiveruserid as receiver4_,
internalme0_.receivergroupid as receiver5_, internalme0_.subject as subject, internalme0_.message as message, internalme0_.hasbeenread as hasbeenr8_, internalme0_.timesent as timesent,
internalme0_.messagetype as message10_ from pixel_internalmessage internalme0_, pixel_user user1_, pixel_group group2_ where (internalme0_.senderuserid=user1_.id or internalme0_.sendergroupid=group2_.id) and ((internalme0_.receiveruserid=1 )) order by user1_.username DESC , group2_.name DESC


So, the big question, the one thats kept me pacing back and forth from guitar to computer all day, is how do i get the HQL to produce the above SQL?

Any suggestions? Any help would be greatly appretiated.

Jay @ Pixelknowledge.com :: Web solutions.


Top
 Profile  
 
 Post subject: Could it have to do with a join?
PostPosted: Thu Feb 10, 2005 1:38 am 
Newbie

Joined: Wed Feb 09, 2005 4:27 am
Posts: 3
Could this possibly have something to do with me needing to perform a join? (left, right, outer) ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 10, 2005 1:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Impossible to tell without a mapping document (sigh).


Top
 Profile  
 
 Post subject: the mapping xml file.
PostPosted: Thu Feb 10, 2005 2:07 pm 
Newbie

Joined: Wed Feb 09, 2005 4:27 am
Posts: 3
sorry, didn't think it was that relevant for the query.

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

<hibernate-mapping>
    <class name="org.pixel.core.InternalMessage" table="opus_internalmessage" lazy="true">

        <id name="id" column="id" unsaved-value="0">
            <generator class="increment"/>
        </id>

        <many-to-one name="sender" column="senderuserid" class="org.pixel.core.User" cascade="none" />

        <many-to-one name="senderGroup" column="sendergroupid" class="org.pixel.core.Group" cascade="none"  />

        <many-to-one name="receiver" column="receiveruserid" class="org.pixel.core.User" cascade="none" />

        <many-to-one name="receiverBand" column="receivergroupid" class="org.pixel.core.Group" cascade="none"  />

        <property name="subject" column="subject" length="200" not-null="true"/>
        <property name="message" column="message" length="5000" not-null="true"/>
        <property name="hasBeenRead" column="hasbeenread"/>
        <property name="timeSent" column="timesent" not-null="true"/>
        <property name="messageType" column="messagetype" not-null="true"/>

        </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.  [ 4 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.