-->
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: createNativeQuery( "select count(*) ... FAILS
PostPosted: Fri Feb 16, 2007 4:03 pm 
Beginner
Beginner

Joined: Fri Jan 27, 2006 4:20 am
Posts: 22
Stack:
JDK 5.0
Hibernate-3.2.x.GA
Hibernate Annotations and EntMgr 3.2.1
MySQL Server 5.1.11
MySQL Connector/J 5.0.3 and 3.1.10

Hi,

Why is it that on these statements:

Code:
EntityManager em = emf.createEntityManager();
Query query = em.createNativeQuery( "select count(*) from helloworld.tblmessages" );
System.out.println( "Number of rows: " + query.getSingleResult().toString() );


the first line throws this exception:

Code:
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
   at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
   at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:99)
   at com.samples.jpa.helloworld.JPAHelloWorld.main(JPAHelloWorld.java:85)
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.loader.Loader.doList(Loader.java:2147)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
   at org.hibernate.loader.Loader.list(Loader.java:2023)
   at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
   at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
   at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
   at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:150)
   at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:80)
   ... 1 more
Caused by: java.sql.SQLException: Column '' not found.
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
   at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:955)
   at com.mysql.jdbc.ResultSet.getBigDecimal(ResultSet.java:1226)
   at org.hibernate.type.BigIntegerType.get(BigIntegerType.java:34)
   at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
   at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:139)
   at org.hibernate.loader.custom.CustomLoader$ScalarResultColumnProcessor.extract(CustomLoader.java:474)
   at org.hibernate.loader.custom.CustomLoader$ResultRowProcessor.buildResultRow(CustomLoader.java:420)
   at org.hibernate.loader.custom.CustomLoader.getResultColumnOrRow(CustomLoader.java:317)
   at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:594)
   at org.hibernate.loader.Loader.doQuery(Loader.java:689)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
   at org.hibernate.loader.Loader.doList(Loader.java:2144)
   ... 8 more


where helloworld is the database name and tblmessages is the table name

The exception can be generated using connector/j 5.0.3. If I changed my connector/j to old version such as 3.1.10, no exceptions are generated. But I tried the same query on connector/j 5.0.3 using pure JDBC and worked just fined. So I can't assume that the connector/j 5.0.3 is at fault.

Looking at the exception above, it seems hibernate generated a column named '' ? I dont know what's really happening there, I've tried to debug using the source but i keep on getting FileNotFound exception (which dont happen when not debugging).

Any help will be appreciated.

If you think seeing the source, mapping and config files are neccessary, just reply and ill post it.

I already tried looking at the forum and searching the web or maybe I just can't make the right keywords.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 16, 2007 4:26 pm 
Beginner
Beginner

Joined: Fri Jan 27, 2006 4:20 am
Posts: 22
Mmm..

I tried using connector/j 5.0.4, and no problems, no exception. The count from createNativeQuery also returns consistently with the JDBC's query.

I think something behind lurks in a wrong way.

Is con/j 5.0.3 really buggy or just imcompatible with hibernate?

I just thought this maybe worth mentioning on the docs.

Can anybody confirm this?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 20, 2007 7:34 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Probably a bug in their JDBC metadata APIs.

_________________
Emmanuel


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.