Hibernate调用存储过程 报错找不到存储过程****
创建存储SqlServer2005存储过程的语句
create procedure pro_GetAllStudent
as
select * from student
go
Student.hbm.xml里的配置
<sql-query name="pro_GetAllStudent" callable="true">
<return alias="student" class="com.Student">
<return-property name="stuid" column="stuid"/>
<return-property name="stuname" column="stuname"/>
<return-property name="stuaddress" column="stuaddress"/>
</return>
{call pro_GetAllStudent()}
</sql-query>
Test.java里的main方法调用
SessionFactory sf=HibernateSessionFactory.getSessionFactory();
Session session=sf.openSession();
//System.out.println(session==null);
List list = session.getNamedQuery("pro_GetAllStudent").list();
for (int i = 0; i < list.size(); i++) {
Student user = (Student) list.get(i);
System.out.print("stuid: " + user.getStuid());
System.out.print("stuname: " + user.getStuname());
System.out.println("stuaddress: " + user.getStuaddress());
}
以下是异常信息:
Exception in thread "main"
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:2223)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
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:152)
at com.Test.main(Test.java:20)
Caused by:
com.microsoft.sqlserver.jdbc.SQLServerException: 找不到存储过程 'pro_GetAllStudent'。
at com.microsoft.sqlserver.jdbc.
SQLServerException.makeFromDatabaseError(Unknown Source)
at com.microsoft.sqlserver.jdbc.IOBuffer.processPackets(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.sendExecute(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecute(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(Unknown Source)
at org.hibernate.dialect.SybaseDialect.getResultSet(SybaseDialect.java:186)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:193)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1784)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
请高手帮忙解决,感激不尽!
------解决方案--------------------
你创建到哪个数据库里面了啊?呵呵呵!
------解决方案--------------------
会不会是驱动不行啊?
印象中这些驱动都是在sql ser