-->
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: Problem when calling storedprocedure via sql-named-query
PostPosted: Thu Nov 22, 2007 12:52 pm 
Newbie

Joined: Thu Nov 22, 2007 11:43 am
Posts: 8
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2
Mapping documents:
<sql-query name="fetchDependencyForTask">
<return alias="rcmTask"
class="Task">
<return-property name="systemCode" column="sub_sys_cod"/>
<return-property name="taskCode" column="tsk_cod"/>
<return-property name="taskStatus" column="stat_cod"/>
<return-property name="lastModified" column="lst_mod_dt"/>
<return-property name="soFar" column="duration"/>
<return-property name="lastTime" column="lst_duration"/>
<return-property name="eta" column="eta"/>
<return-property name="instanceNumber" column="prcr_inst"/>
<return-property name="taskNumber" column="sts_inl_no"/>
</return>
{ callsp_fe_getDpyForTask (?,?)}
</sql-query>



Full stack trace of any exception that occurs:
2007-11-22 15:28:36,946 [main] WARN org.hibernate.util.JDBCExceptionReporter [] - SQL Error: 0, SQLState: S0022
2007-11-22 15:28:36,946 [main] ERROR org.hibernate.util.JDBCExceptionReporter [] - S0022: Invalid column name 'stt5_60_0_'.
2007-11-22 15:28:37,009 [main] ERROR com.bnpparibas.risk.collateralrisk.dao.RcmTaskDao [] - Failedt to fetch Dependency For Task MY_TASK
org.springframework.orm.hibernate3.HibernateJdbcException: JDBC exception on Hibernate data access; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
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:2214)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
at org.hibernate.loader.Loader.list(Loader.java:2090)
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.springframework.orm.hibernate3.HibernateTemplate$32.doInHibernate(HibernateTemplate.java:906)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:362)
at org.springframework.orm.hibernate3.HibernateTemplate.findByNamedQuery(HibernateTemplate.java:897)
at com.bnpparibas.risk.collateralrisk.dao.BaseDao.executeStoredProcedure(BaseDao.java:80)
at com.bnpparibas.risk.collateralrisk.dao.RcmTaskDao.fetchDependencyForTask(RcmTaskDao.java:179)
at com.bnpparibas.risk.collateralrisk.dao.RcmTaskDaoTest.testFetchDependencyForTask(RcmTaskDaoTest.java:270)
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:585)
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.textui.TestRunner.doRun(TestRunner.java:116)
at com.intellij.rt.execution.junit.IdeaTestRunner.doRun(IdeaTestRunner.java:65)
at junit.textui.TestRunner.doRun(TestRunner.java:109)
at com.intellij.rt.execution.junit.IdeaTestRunner.startRunnerWithArgs(IdeaTestRunner.java:24)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:118)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
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:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: java.sql.SQLException: S0022: Invalid column name 'stt5_60_0_'.
at com.sybase.jdbc3.jdbc.ErrorMessage.raiseError(Unknown Source)
at com.sybase.jdbc3.tds.TdsResultSet.findColumnByLabel(Unknown Source)
at com.sybase.jdbc3.jdbc.SybResultSet.findColumn(Unknown Source)
at com.sybase.jdbc3.jdbc.SybResultSet.getString(Unknown Source)
at org.hibernate.type.StringType.get(StringType.java:18)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:102)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2046)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1371)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1299)
at org.hibernate.loader.Loader.getRow(Loader.java:1197)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:568)
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:2211)
... 33 more

Name and version of the database you are using:
Sybase 12.5
The generated SQL (show_sql=true):

{ call sp_fe_getDpyForTask (?,?)}
Debug level Hibernate log excerpt:


Hi all,
i am getting that disaster exception when calling stored procedure via sql native query.
Or, let's be precise. I have 15 sql-native queries that calls stored procedures.
10 works, and 5 does not, and the common trait between the five failing is that they are doing some operations with dates. (below is sybase code)

set lst_duration = datediff(mi,r.stt_dt,r.end_dt)
, eta = dateadd (mi,datediff(mi,r.stt_dt,r.end_dt),t.lst_mod_dt )


and all of those are returning same error
Invalid column name 'stt5_60_0_'

i guess that column is somehow the product of doing date differences..
ALL stored procedure that fails are all doing the same thing with dates

i was wondering if anyone came across this before, and what could be the solution...

anyone could help?

thanks and regards
marco


Top
 Profile  
 
 Post subject: I found something...
PostPosted: Thu Jun 19, 2008 10:00 am 
Newbie

Joined: Mon Feb 13, 2006 10:26 am
Posts: 6
I had exactly the same problem. The strange thing was that for some sql queries, Hibernate doesn't return an error but for others it does so. I did the following thing:
Previous mapping:
<sql-query name="SP" callable="true">
<return class="myClass">
<return-property name="a" column="A"/>
<return-property name="b" column="B"/>
</return>
{ call SP(:c) }
</sql-query>

Current mapping:
<sql-query name="SP" callable="true">
<return class="myClass"/>
{ call SP(:c) }
</sql-query>

Of course, my stored procedure had to be changed in order to return columns that have the names of the mapped class.

Apparently, there is a problem when a SQLCustomQuery uses DefaultEntityAliases. But what is strange is that I have some sql queries with return-properties that work fine... Tell me if my solution helped you!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 23, 2008 10:51 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
SQLGrammar is commonly triggered by an incorrect mapping. Make sure all your column and database names are correct in your annotations or configuration hbm files.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.