Hi there,
I am trying to execute the stored procedure in hibernate. I am using spring,hibernate,and sql server 2005.
My mapping is like this
Code:
<sql-query name="TestProc" callable="true" read-only="true">
{call RunTestProc(?,?,?,?,?,?,?)}
</sql-query>
and in dao, I can call either
Code:
List<ReturnObjectFromSP> list = this.getHibernateTemplate().findByNamedQuery("TestProc", new Object[]{6,3,9580,2,2,0.1,0});
or
Code:
List<ReturnObjectFromSP> list = this.getSession().getNamedQuery("TestProc")
.setParameter(0, 6)
.setParameter(1, 3)
.setParameter(2, 9580)
.setParameter(3, 2)
.setParameter(4, 2)
.setParameter(5, 0.1)
.setParameter(6, 0).list();
The problem is it returns list of Object, instead of my ReturnObjectFromSP. So I modify the map to specify the return class,return-property. But it throws exception "Caused by: org.hibernate.HibernateException: Errors in named queries: TestProc".Is it because ReturnObjectFromSP is not mapped to any table? But the result from my stored procedure is combination of different tables.
So I have another try by removing the return class,return-property in the map, and add
Code:
List<ReturnObjectFromSP> list = this.getSession().getNamedQuery("TestProc")
.setParameter(0, 6)
.setParameter(1, 3)
.setParameter(2, 9580)
.setParameter(3, 2)
.setParameter(4, 2)
.setParameter(5, 0.1)
.setParameter(6, 0).
.setResultTransformer(Transformers.aliasToBean(ReturnObjectFromSP.class)).list();
with this way, it throws another error like it cannot find the setter for the column into my class.
Can anyone give me an advice?
TIA.