Hibernate执行存储过程报了一个郁闷的异常(Column 'user2_0_0_' not found.)
public static void executeProNoPara() {
// 执行存储过程
Session session = HibernateSessionFactory.getSession();
// SQLQuery sqlQuery = session.createSQLQuery("call test()").addEntity(
// com.ssh.user.User.class); List list = session.getNamedQuery("test").list();
// List list = sqlQuery.list(); User user = null;
for (int i = 0; i < list.size(); i++) {
user = (User) list.get(i);
System.out.println(user.getUserName() + " " + user.getPassword());
}
}
上面的代码是我调用存储过的代码,其中标红的部分是以SQLQuery的方式调用的,没有问题,但是我个人觉得这种方式不是很好,久用 了上面没有注释的方法,但是报了一个很奇怪的异常
2013-01-03 16:48:11,531 WARN [org.hibernate.util.
JDBCExceptionReporter] - SQL Error: 0, SQLState: S0022
2013-01-03 16:48:11,546 ERROR [org.hibernate.util.JDBCExceptionReporter] - Column 'user2_0_0_' not found.
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:2147)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
at org.hibernate.loader.Loader.list(Loader.java:2023)
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 com.ssh.test.Test.executeProNoPara(Test.java:71)
at com.ssh.test.Test.main(Test.java:46)
Caused by:
java.sql.SQLException: Column 'user2_0_0_' not found.
at
com.mysql.jdbc.SQLError.create
SQLException(SQLError.java:1073)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1144)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5610)
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:2031)
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)