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.