-->
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: Sql translation error on Count(*) query - x0_0_
PostPosted: Wed Mar 10, 2004 1:54 pm 
Newbie

Joined: Wed Mar 10, 2004 1:37 pm
Posts: 2
I'm using Hibernate 2.1.2, mysql 4.0.14, old mysql driver (org.gjt.mm.mysql..)

Code:
SessionFactory sf = new Configuration().configure().buildSessionFactory();
Session sess = sf.openSession();
try {
    tx = sess.beginTransaction();
    int bigcount =  ( (Integer) sess.iterate("select count(*) from problems").next() ).intValue();
} finally {
    sess.close();


I continually get hsql translation errors:

Code:
DEBUG net.sf.hibernate.hql.QueryTranslator  - HQL: select count(*) from problems
SQL: select count(*) as x0_0_ from
DEBUG net.sf.hibernate.hql.QueryTranslator  - SQL: select count(*) as x0_0_ from
about to open: 0 open PreparedStatements, 0 open ResultSets
DEBUG net.sf.hibernate.impl.BatcherImpl  - about to open: 0 open PreparedStatements, 0 open ResultSets
select count(*) as x0_0_ from
DEBUG net.sf.hibernate.SQL  - select count(*) as x0_0_ from
preparing statement
DEBUG net.sf.hibernate.impl.BatcherImpl  - preparing statement
SQL Exception
java.sql.SQLException: Syntax error or access violation: You have an error in your SQL syntax.  Check the manual that corresponds to your My
SQL server version for the right syntax to use near '' at line 1
        at org.gjt.mm.mysql.MysqlIO.sendCommand(Unknown Source)
        at org.gjt.mm.mysql.MysqlIO.sqlQueryDirect(Unknown Source)
        at org.gjt.mm.mysql.Connection.execSQL(Unknown Source)
        at org.gjt.mm.mysql.PreparedStatement.executeQuery(Unknown Source)
        at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
        at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:795)
        at net.sf.hibernate.loader.Loader.doQuery(Loader.java:189)
        at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
        at net.sf.hibernate.loader.Loader.doList(Loader.java:950)
        at net.sf.hibernate.loader.Loader.list(Loader.java:941)
        at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:834)
        at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1512)
        at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1491)
        at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1483)


I've tried the query numerous ways, but this is the recommended way in the FAQ, so this should at least work. Anyone know what the problem is here?

Other select queries into this db & table work fine, just not the count.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 10, 2004 1:58 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
is "problems" really a class you have mapped?


Top
 Profile  
 
 Post subject: That was the problem...
PostPosted: Wed Mar 10, 2004 2:15 pm 
Newbie

Joined: Wed Mar 10, 2004 1:37 pm
Posts: 2
Thanks Michael,
that got my brain thinking. I have a class Problem mapped to the table problems. I was thinking of it as a straight SQL call, instead of using a data object. That did the trick when I changed it from
Code:
select count(*) from problems

to
Code:
select count(*) from Problem

Works now.


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.