-->
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: nested AND
PostPosted: Fri Mar 12, 2004 4:25 pm 
Newbie

Joined: Tue Feb 10, 2004 9:26 am
Posts: 12
Hi All.

I am running hibernate 1.2 with postgresql 7.2.4.
I would like to do a HQL query like the following WHERE clause.

Code:
SELECT table
FROM table IN class com.sys.hib.Table, item IN class com.sys.hib.Item
WHERE table.tableId = item.tableId
AND NOT (table.statusId IN ('bad','worse') AND table.startTime > item.eolTime)
AND table.tableId =:passedTableId


The problem is the query in psql works fine but in hibernate the nested part of the query is always met even if it shouldn't be.

I also tried the following with the same result:

Code:
AND (table.statusId NOT IN ('bad','worse') OR table.startTime < item.eolTime)

I am not sure if this is fixed in a newer version of hibernate.
If so it could be the reason I need to get around to upgrading.

Thanks in advance.
Ian...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 12, 2004 8:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I'm sorry? What is the problem???

Some generated SQL?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 13, 2004 6:40 am 
Newbie

Joined: Tue Feb 10, 2004 9:26 am
Posts: 12
Code:
2004-03-13 10:20:47,517 DEBUG [cirrus.hibernate.impl.SessionFactoryImpl] prepare
d statement get: SELECT table.tableId, table.startTime as startTime FROM table table, item item WHERE (table.tableId=item.tableId )AND((table.statusid not in('bad' , 'worse'))or(table.startTime<= item.eolTime))AND(table.tableId =?)


Sorry I should have made it clearer.
If I run the hibernate generated sql in psql (replacing the ?) the query runs as expected.
Basically only return table entries that are either not in the given statuses or the start time is earlier than the eolTime.
In hibernate it always returns the table regardless of status or times.

Cheers.
Ian.


Top
 Profile  
 
 Post subject: WHERE clause on named param timestamp
PostPosted: Sat Mar 13, 2004 8:27 am 
Newbie

Joined: Tue Feb 10, 2004 9:26 am
Posts: 12
Sorry I have failed to include some important information.
Also I was chasing the wrong problem, sorry if I wasted your time. :(

I am actually passing a named parameter date (java.util.Date) instead of the item.eolTime which hibernate logs as 'binding '13 March 2004' to parameter: 1'
hence it was always matching the date as they where all set to today though the times where different so the nested AND was working fine.
Though I want to do second precision checking for this date.
I use the Query.setDate("item_eolTime",java.util.Date()) to set this named parameter.

ie. AND NOT (table.statusId IN ('bad','worse') AND table.startTime > :item_eolTime)
Is there something I should be doing to in order to not loose the time part of java.util.Date ?

Cheers.
Ian.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 13, 2004 8:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Yes, use query.setTimestamp()


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 13, 2004 8:47 am 
Newbie

Joined: Tue Feb 10, 2004 9:26 am
Posts: 12
I'm extremely sorry for not researching properly before posting.
I found on forum "Hibernate's ability to query time" the solution to the actual problem I was having.
I am now using Query.setTimestamp(String, java.util.Date) and it works beautifully.

Sorry again for time wasting.
Thank you very much for persisting with me in this wild goose chase.
Cheers.
Ian.


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.