Hibernate version: 3.0
Name and version of the database you are using: Sybase 12.5
Something similar has been discussed here a few times before, but none of those posts provided a solution to my problem.
I get the following exception while attempting to create a temporary table with JDBC using the connection obtained from Hibernate session:
com.sybase.jdbc2.jdbc.SybSQLException: The 'CREATE TABLE' command is not allowed within a multi-statement transaction in the 'tempdb' database.
Full stack trace:
Caused by: com.sybase.jdbc2.jdbc.SybSQLException: The 'CREATE TABLE' command is not allowed within a multi-statement transaction in the 'tempdb' database.
at com.sybase.jdbc2.tds.Tds.processEed(Tds.java:2636)
at com.sybase.jdbc2.tds.Tds.nextResult(Tds.java:1996)
at com.sybase.jdbc2.jdbc.ResultGetter.nextResult(ResultGetter.java:69)
at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:204)
at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:187)
at com.sybase.jdbc2.jdbc.SybStatement.updateLoop(SybStatement.java:1642)
at com.sybase.jdbc2.jdbc.SybStatement.executeUpdate(SybStatement.java:1625)
at com.sybase.jdbc2.jdbc.SybStatement.executeUpdate(SybStatement.java:414)
at xxx.HibernateSession.createTempAuditTable(HibernateSession.java:453)
Following is the
Code (1):
Code:
Session session = sessionFactory.openSession();
Connection conn = session.connection();
Statement stmt = con.createStatement();
stmt.executeUpdate("create table #whatever(col1 int)");
What's interesting is that I don't get any exceptions when I do the same using a JDBC connection created from scratch:
Code (2):
Code:
Class.forName("com.sybase.jdbc2.jdbc.SybDriver");
Connection conn = DriverManager.getConnection(dbUrl, uid, pwd);
conn.setAutoCommit(false);
Statement stmt = con.createStatement();
stmt.executeUpdate("create table #whatever(col1 int)");
Auto commit is set to false in BOTH cases (automatically by Hibernate in first and explicitely in code in the second) and I do not explicitely begin a new transaction in either case.
So what is different about the JDBC connection obtained through Hibernate?
Thanks, Rishabh