Hi,
We have recently upgraded our SQL Server 2005 JDBC driver from version 1.1 to version 1.2. We have received the exception below when executing a native query. We have refined the issue down to the fact that when executing a native query hibernate calls the
Code:
PreparedStatement.executeQuery()
api from the
Code:
getResultSet(PreparedStatement ps)
method of the org.hibernate.jdbc.AbstractBatcher class. The exception states that a result set was not returned. The Microsoft forum has said that the updated driver has been brought into line with the JDBC 3.0 specification which requires a resultset be returned from an executeQuery() call. The instance in which we call the createNativeQuery is
Code:
Query q = entityManager.createNativeQuery("INSERT INTO " + seqName + " DEFAULT VALUES SELECT @@IDENTITY AS 'I'");
Object o = q.getSingleResult();
The insert statement does not return a result set and this is causing an issue with the updated driver. Is it possible to execute an insert statement via the createNativeQuery api using the JDBC 3.0 specification?
Hibernate version:3.2 cr2
Full stack trace of any exception that occurs:org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2148)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:118)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1684)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:164)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:756)
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:63)
... 23 more
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
... 31 more
Name and version of the database you are using: SQL Server 2005