-->
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: HQL : From .. OK with MS_SQLServer but not with MySQL
PostPosted: Tue Jul 05, 2005 3:21 pm 
Beginner
Beginner

Joined: Wed May 12, 2004 4:27 am
Posts: 21
Location: Montreux (CH)
Hello,

I am running a test on MS SQL Server and MySQL4 with Hibernate3.
Using their own hql dialect

I've got a table core_password_logs like this :
(class_id, item_id, version, .....)

This is OK in MS SQL Server
Code:
SELECT     *
FROM         core_password_logs V
WHERE     (version IN
                          (SELECT     MAX(version)
                            FROM          core_password_logs W
                            WHERE      W.item_id = V.item_id))


the ID is a composite key with (class_id,item_id)
the HQL is :
Code:
query="From HibPasswordLog PWD Where
            PWD.id.version in (select max(PWDmax.id.version)
            from HibPasswordLog PWDmax
            where PWDmax.id.classId = PWD.id.classId
                  AND PWDmax.id.itemId = PWD.id.itemId)";



and MySQL does not like it at all !!

Code:
SQL Error: 1064, SQLState: 42000
Syntax error or access violation: You have an error in your SQL syntax.
Check the manual that corresponds to your MySQL server version for the right syntax to use near 'select max(hibpasswor1_.version) from core_password_logs hib
pas
Can't load class mapping.password.HibPasswordLog
org.hibernate.exception.SQLGrammarException: could not execute query
        at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.loader.Loader.doList(Loader.java:1596)
        at org.hibernate.loader.Loader.list(Loader.java:1577)
        at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
        at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
        at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
        at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)




ANY IDEA ? how should be the right sql and hql query ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 06, 2005 5:21 am 
Beginner
Beginner

Joined: Wed Feb 23, 2005 2:23 pm
Posts: 21
Location: Pescara, italy
hello samfra,

does MySQL support subqueries nowadays?
I have read some time ago that MySql does not allow subqueries...

Gruss
Kai


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 06, 2005 6:58 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
MySQL supports subqueries since version 4.1.x.
It's not a bad idea to tell us your mappings.

Best regards
Sven


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.