Reputation: 997
I am having the following statement.
result = (BigDecimal)m_EntityManager.createNativeQuery(query).getSingleResult();
Query is:
select sum(field5) from myTable where field1 = '?#This' and
field2=1234 and field3 IN ('7183328608','7187931685','7187931686')
Hibernate version is: 3.2.1ga
When ran against development and QA servers, we are having no problem However, when deploying to production, there is an exception/error is observed.
ERROR: [BillSessionEJB: ] Error in runSingleResultNativeQuery(): running query:
select sum(field5) from myTable where field1 = '?#This' and
field2=1234 and field3 IN ('7183328608','7187931685','7187931686')
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not
execute query 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.broadview.billing.billingdataservices.beans.BillSessionEJB.runSingleResultNativeQuery(BillSession
Development and QA server are running SQLSERVER 2012, Production is running 2005. Is there a difference?
My only thought is that to put a name for the column sum.
as 'Total' .. in select
Any comments, ?? Please share thoughts.
Upvotes: 0
Views: 66
Reputation: 36
Your query seems ok. Are the column names correct? The documentation of SQLGrammarException hints that:
Implementation of JDBCException indicating that the SQL sent to the database server was invalid (syntax error, invalid object references, etc).
So the syntax is just one of the possible culprits. Try to run your query by hand on production and see what the DB tells you.
Upvotes: 1