-->
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.  [ 2 posts ] 
Author Message
 Post subject: problem with createSQLQuery
PostPosted: Wed May 03, 2006 1:56 pm 
Newbie

Joined: Mon Feb 09, 2004 11:14 am
Posts: 16
Hibernate version: 3.0

I am trying to get the following query to work:

Session session = HibernateAbstractSessionUtil.getCurrentSession();
Double query = (Double) session.createSQLQuery(
"SELECT SUM(postAmount) sumPostAmount " +
" FROM ( SELECT (CASE WHEN ENTRY_TYPE = 'DEBIT' THEN POST_AMOUNT ELSE POST_AMOUNT * -1 END) postAmount " +
" from S_GL_ENTRY_E11 ) e11")
.addScalar("sumPostAmount", Hibernate.DOUBLE)
.addScalar("postAmount", Hibernate.DOUBLE)
.uniqueResult();

sumOfPostAmounts = query.doubleValue();




The query works fine through my SQuirrel SQL client. But Hibernate is telling me about an invalid column name. Can someone suggest some ideas for me? Is this a driver issue?

The error message is as follows:

ERROR [5/03/06 13:29] HibernateAbstractDAO shaw.spectrum.core.service.ServiceErrorBean@cd8e77[User=defaultUser,Key=SP00365,Category=AUDIT,Severity=1,Description=Error reading Transaction using transaction.baseId 84.,Cause=org.hibernate.exception.SQLGrammarException: could not execute query could not execute query
[Ljava.lang.StackTraceElement;@1d4179]
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.custom.CustomLoader.list(CustomLoader.java:112)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1414)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:153)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:603)
at shaw.spectrum.core.transaction.persistence.TransactionDAOImpl.sumOfSimpleInterestForGivenPeriod(TransactionDAOImpl.java:540)
at shaw.spectrum.core.transaction.test.TransactionDAOTest.doTestSumOfSimpleInterestForGivenPeriod(TransactionDAOTest.java:92)
at shaw.spectrum.core.transaction.test.TransactionDAOTest.testDataBaseFunctions(TransactionDAOTest.java:80)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.sql.SQLException: Invalid column name
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
at oracle.jdbc.driver.OracleStatement.get_column_index(OracleStatement.java:6218)
at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1557)
at oracle.jdbc.driver.OracleResultSet.getDouble(OracleResultSet.java:1625)
at org.hibernate.type.DoubleType.get(DoubleType.java:20)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:94)
at org.hibernate.loader.custom.CustomLoader.getResultColumnOrRow(CustomLoader.java:133)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:329)
at org.hibernate.loader.Loader.doQuery(Loader.java:412)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
... 23 more


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 4:02 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you call addScalar for a column that is not in the select.

_________________
Max
Don't forget to rate


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