-->
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.  [ 13 posts ] 
Author Message
 Post subject: SQL != HQL?
PostPosted: Tue Mar 30, 2004 3:40 am 
Beginner
Beginner

Joined: Tue Mar 23, 2004 4:18 pm
Posts: 45
SELECT urls.url, urls.id FROM f4t.hibernate.Url as urls
WHERE urls.id = html.urlid
AND
(
urls.url LIKE 'http://foo/%'"
OR urls.url LIKE 'http://bar/%'"
)

return 3768 rows while

SELECT urls.url, urls.id FROM urls
WHERE urls.id = html.urlid
AND
(
urls.url LIKE 'http://foo/%'"
OR urls.url LIKE 'http://bar/%'"
)


does return only 3656 rows.

Why is that? And which result is correct actually?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 3:48 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Look at the SQL Hibernate generates. This is much better than guessing.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 4:17 am 
Beginner
Beginner

Joined: Tue Mar 23, 2004 4:18 pm
Posts: 45
christian wrote:
Look at the SQL Hibernate generates. This is much better than guessing.


I did:

select url0_.url as x0_0_, url0_.id as x1_0_ from urls url0_ where (url0_.id=html.urlid )AND((url0_.url LIKE 'http://foo/%' )OR(url0_.url LIKE 'http://bar/%' ))

:-)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 4:19 am 
Beginner
Beginner

Joined: Tue Mar 23, 2004 4:18 pm
Posts: 45
tcn wrote:
christian wrote:
Look at the SQL Hibernate generates. This is much better than guessing.


I did:

select url0_.url as x0_0_, url0_.id as x1_0_ from urls url0_ where (url0_.id=html.urlid )AND((url0_.url LIKE 'http://foo/%' )OR(url0_.url LIKE 'http://bar/%' ))

:-)


...which actually does return 3656 rows :-\

I did the counting this way:

Iterator iter = session.createQuery(query).iterate();
int i = 0;
for(;iter.hasNext();iter.next()) i++;
System.out.println(i);

And this outputs 3768...(?!).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 5:10 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
As I understand both queries are invalid and must return an error not a result.

SELECT urls.url, urls.id FROM urls
WHERE urls.id = html.urlid
^^^^^^
AND
(
urls.url LIKE 'http://foo/%'"
OR urls.url LIKE 'http://bar/%'"
)


Are you sure you executed this query ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 6:04 am 
Newbie

Joined: Wed Feb 25, 2004 11:41 pm
Posts: 19
Location: China
try to use
List l = session.createQuery(query).list();

System.out.println(l.size());

how many rows you get...

_________________
who can tell me why?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 7:32 am 
Beginner
Beginner

Joined: Tue Mar 23, 2004 4:18 pm
Posts: 45
KaKaXi wrote:
try to use
List l = session.createQuery(query).list();

System.out.println(l.size());

how many rows you get...


3768...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 7:33 am 
Beginner
Beginner

Joined: Tue Mar 23, 2004 4:18 pm
Posts: 45
baliukas wrote:
As I understand both queries are invalid and must return an error not a result.

SELECT urls.url, urls.id FROM urls
WHERE urls.id = html.urlid
^^^^^^
AND
(
urls.url LIKE 'http://foo/%'"
OR urls.url LIKE 'http://bar/%'"
)


Are you sure you executed this query ?


The query is valid and executes.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 8:47 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
SELECT urls.url, urls.id
FROM urls
WHERE urls.id = html.urlid
AND
(
urls.url LIKE 'http://foo/%'"
OR urls.url LIKE 'http://bar/%'"
)

Is "html" a custom type field in "urls" table ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 9:16 am 
Beginner
Beginner

Joined: Tue Mar 23, 2004 4:18 pm
Posts: 45
baliukas wrote:
SELECT urls.url, urls.id
FROM urls
WHERE urls.id = html.urlid
AND
(
urls.url LIKE 'http://foo/%'"
OR urls.url LIKE 'http://bar/%'"
)

Is "html" a custom type field in "urls" table ?


http://forum.hibernate.org/viewtopic.ph ... 167ac813b4


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 10:05 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
This SQL is invalid, it works on postgresql, but this is more bug than feature in parser to support queries like "SELECT 1" and I am not sure it returns expected results.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 10:18 am 
Beginner
Beginner

Joined: Tue Mar 23, 2004 4:18 pm
Posts: 45
baliukas wrote:
This SQL is invalid, it works on postgresql, but this is more bug than feature in parser to support queries like "SELECT 1" and I am not sure it returns expected results.


Ok, and what would the correct HQL look like?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 11:18 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
As I understand you want this:

SELECT urls.url, urls.id
FROM f4t.hibernate.Url as urls
WHERE urls.url LIKE 'http://foo/%'" OR urls.url LIKE 'http://bar/%'"


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