关于网友提出的“ Hibernate调用存储过程 报错找不到存储过程”问题疑问,本网通过在网上对“ Hibernate调用存储过程 报错找不到存储过程”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: Hibernate调用存储过程 报错找不到存储过程
描述: 创建存储SqlServer2005存储过程的语句
create procedure pro_GetAllStudent
as
select * from student
go
Student.hbm.xml里的配置
{call pro_GetAllStudent()}
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)
请高手帮忙解决,感激不尽!
解决方案1: 有点意思
在看
解决方案2: 冒搞过,学习...
解决方案3: 学习。
解决方案4: 你的存储过程在你所使用的数据库用户下吗?
解决方案5: 会不会是驱动不行啊?
印象中这些驱动都是在sql server2000上用的,不知道到2005上会不会有问题。
你试着直接调用存储过程看看,类似这样的:
tx = session.beginTransaction();
Connection con=session.connection();
String procedure = "{call pro_GetAllStudent()}";
CallableStatement cstmt = con.prepareCall(procedure);
cstmt.executeUpdate();
tx.commit();
解决方案6: 你创建到哪个数据库里面了啊?呵呵呵!
以上介绍了“ Hibernate调用存储过程 报错找不到存储过程”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/2922115.html