运行以下程序是总是抛出一个
异常:
Caused by: com.sybase.jdbc3.jdbc.SybSQLException: The datastream for token 236 should only be sent after other datastreams. It
can not be a
command datastream on it's own. This is an internal error.
具体方法为:
public List<?> executeProcedure(Class<?> entityClass, String procedure,
String requestId) {
List<?> list = new ArrayList<HibernateProcedureObject>();
try {
session = getCurrentSession(entityClass);
SQLQuery query = session.createSQLQuery(procedure);
query.setString(0, requestId);
list = query.list();
} catch (HibernateException e) {
e.printStackTrace();
logger.log(RMTManagementLevel.ERROR, e);
} finally {
this.closeConnection();
}
return list;
}
异常为:
org.
hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2536)
at org.hibernate.loader.Loader.listIgnore
QueryCache(Loader.java:2276)
at org.hibernate.loader.Loader.list(Loader.java:2271)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:316)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1842)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:157)
at com.eagle.utils.hibernatePersistence.HibernateSessionFactory.executeProcedure(HibernateSessionFactory.java:245)
at com.eagle.utils.hibernatePersistence.Test.testAuctionData_Procedure(Test.java:498)
at com.eagle.utils.hibernatePersistence.Test.main(Test.java:512)
Caused by: com.sybase.jdbc3.jdbc.SybSQLException: The datastream for token 236 should only be sent after other datastreams. It can not be a command datastream on it's own. This is an internal error.
at com.sybase.jdbc3.tds.Tds.processEed(Tds.java:2942)
at com.sybase.jdbc3.tds.Tds.nextResult(Tds.java:2246)
at com.sybase.jdbc3.tds.Tds.getResultSetResult(Tds.java:2853)
at com.sybase.jdbc3.tds.TdsCursor.open(TdsCursor.java:295)
at com.sybase.jdbc3.jdbc.SybStatement.executeQuery(SybStatement.java:1659)
at com.sybase.jdbc3.jdbc.SybPreparedStatement.executeQuery(SybPreparedStatement.java:97)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
at org.hibernate.loader.Loader.doQuery(Loader.java:802)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.doList(Loader.java:2533)
... 9 more
解决方案:
只能利用传统的Connection和ResultSet的形式:
resultSet = null;
try {
cstmt = getCurrentSession(entityClass).connection().prepareCall(
"{call " + procedure + "}");
resultSet = cstmt.executeQuery();
} catch (HibernateException e) {
this.closeConnection();
e.printStackTrace();
logger.log(RMTManagementLevel.ERROR, e);
} catch (SQLException e) {
this.closeConnection();
e.printStackTrace();
logger.log(RMTManagementLevel.ERROR, e);
}