org.hibernate.engine.jdbc.spi.SqlExceptionHelper: Invalid column number (23)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

org.hibernate.engine.jdbc.spi.SqlExceptionHelper: Invalid column number (23)

Marc Elliott
Hi All,

I'm trying to update my application to Hibernate 4.1.x and having some troubles related to using the Hibernate JDBC connection with DBUnit and the Merlia.jar JDBC driver for SQL Server.

Essentially, I have code in a unit that that attempts to use DBUnit 2.4.7 to load my test data within the Hibernate doWork callback:

this.getSessionFactory()
.getCurrentSession()
.doWork(new SetupDBUnitDataWorkImpl(getTestData(),
DatabaseOperation.CLEAN_INSERT));

... the Work code looks like this:

public void execute(Connection connection) throws SQLException {
try {
IDatabaseConnection conn = new DatabaseConnection(connection);
FlatXmlDataSetBuilder b = new FlatXmlDataSetBuilder();
FlatXmlDataSet ds = b.build(getClass().getClassLoader()
.getResourceAsStream(this.testData));
this.databaseOperation.execute(conn, ds);
} catch (DatabaseUnitException e) {
e.printStackTrace();
}
}

... when I attempt to run the test I get the Hibernate GenericJDBCException with this abbreviated stack:

org.hibernate.exception.GenericJDBCException: Invalid column number (23). A number between 1 and 22 is valid.
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.proxy.AbstractResultSetProxyHandler.continueInvocation(AbstractResultSetProxyHandler.java:108)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
at $Proxy91.getString(Unknown Source)
at org.dbunit.util.SQLHelper.createColumn(SQLHelper.java:398)
at org.dbunit.database.DatabaseTableMetaData.getColumns(DatabaseTableMetaData.java:333)
at org.dbunit.dataset.AbstractTableMetaData.getColumnIndex(AbstractTableMetaData.java:106)
at org.dbunit.operation.AbstractOperation.getOperationMetaData(AbstractOperation.java:89)
at org.dbunit.operation.AbstractBatchOperation.execute(AbstractBatchOperation.java:140)
at org.dbunit.operation.CompositeOperation.execute(CompositeOperation.java:79)
at com.mathworks.internal.test.SetupDBUnitDataWorkImpl.execute(SetupDBUnitDataWorkImpl.java:52)
[snip]
Caused by: com.inet.tds.at: Invalid column number (23). A number between 1 and 22 is valid.
at com.inet.tds.aq.a(Unknown Source)
at com.inet.tds.p.b(Unknown Source)
at com.inet.tds.ab.getObject(Unknown Source)
at com.inet.tds.ab.getString(Unknown Source)
at com.inet.pool.s.getString(Unknown Source)
at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.engine.jdbc.internal.proxy.AbstractResultSetProxyHandler.continueInvocation(AbstractResultSetProxyHandler.java:104)
... 44 more

... this points me to line 398 in the DBUnit SQLHelper:

       try {
            isAutoIncrement = resultSet.getString(23);
        }
        catch(SQLException e){
            if(logger.isDebugEnabled())
                logger.debug("Could not retrieve the 'isAutoIncrement' property because not yet running on Java 1.5 - defaulting to NO. " +
                        "Table=" + tableName + ", Column=" +columnName, e);
            // Ignore this one here
        }

... what I think is happening is that Hibernate is not willing to ignore the SQLException and that it is somehow detecting it or rethrowing it rather than allowing the DBUnit try/catch to deal with it. Any ideas on how to work around this?


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: org.hibernate.engine.jdbc.spi.SqlExceptionHelper: Invalid column number (23)

Erik G B
Hi Marc,

I am experiencing the same problem. You can try to work around this issue by unwrapping the Connection wrapped by Hibernate. Cast you Connection object to org.hibernate.engine.jdbc.spi.JdbcWrapper, and get hold of the real connection by invoking the getWrappedObject() method. You should then supply the real connection to DbUnit.

final Connection wrappedConnection;
if (connection instanceof JdbcWrapper) {
        wrappedConnection = (Connection) ((JdbcWrapper) connection).getWrappedObject();
} else {
        wrappedConnection = connection;
}
IDatabaseConnection conn = new DatabaseConnection(wrappedConnection);
Regards,
Erik

Marc Elliott wrote
Hi All,

I'm trying to update my application to Hibernate 4.1.x and having some
troubles related to using the Hibernate JDBC connection with DBUnit and the
Merlia.jar JDBC driver for SQL Server.

Essentially, I have code in a unit that that attempts to use DBUnit 2.4.7
to load my test data within the Hibernate doWork callback:

this.getSessionFactory()
 .getCurrentSession()
.doWork(new SetupDBUnitDataWorkImpl(getTestData(),
 DatabaseOperation.CLEAN_INSERT));

... the Work code looks like this:

public void execute(Connection connection) throws SQLException {
 try {
IDatabaseConnection conn = new DatabaseConnection(connection);
FlatXmlDataSetBuilder b = new FlatXmlDataSetBuilder();
 FlatXmlDataSet ds = b.build(getClass().getClassLoader()
.getResourceAsStream(this.testData));
 this.databaseOperation.execute(conn, ds);
} catch (DatabaseUnitException e) {
 e.printStackTrace();
}
}

... when I attempt to run the test I get the Hibernate GenericJDBCException
with this abbreviated stack:

org.hibernate.exception.GenericJDBCException: Invalid column number (23). A
number between 1 and 22 is valid.
 at
org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
at
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
 at
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at
org.hibernate.engine.jdbc.internal.proxy.AbstractResultSetProxyHandler.continueInvocation(AbstractResultSetProxyHandler.java:108)
 at
org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
at $Proxy91.getString(Unknown Source)
 at org.dbunit.util.SQLHelper.createColumn(SQLHelper.java:398)
at
org.dbunit.database.DatabaseTableMetaData.getColumns(DatabaseTableMetaData.java:333)
 at
org.dbunit.dataset.AbstractTableMetaData.getColumnIndex(AbstractTableMetaData.java:106)
at
org.dbunit.operation.AbstractOperation.getOperationMetaData(AbstractOperation.java:89)
 at
org.dbunit.operation.AbstractBatchOperation.execute(AbstractBatchOperation.java:140)
at
org.dbunit.operation.CompositeOperation.execute(CompositeOperation.java:79)
 at
com.mathworks.internal.test.SetupDBUnitDataWorkImpl.execute(SetupDBUnitDataWorkImpl.java:52)
[snip]
Caused by: com.inet.tds.at: Invalid column number (23). A number between 1
and 22 is valid.
at com.inet.tds.aq.a(Unknown Source)
 at com.inet.tds.p.b(Unknown Source)
at com.inet.tds.ab.getObject(Unknown Source)
 at com.inet.tds.ab.getString(Unknown Source)
at com.inet.pool.s.getString(Unknown Source)
 at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
at
org.hibernate.engine.jdbc.internal.proxy.AbstractResultSetProxyHandler.continueInvocation(AbstractResultSetProxyHandler.java:104)
 ... 44 more

... this points me to line 398 in the DBUnit SQLHelper:

       try {
            isAutoIncrement = resultSet.getString(23);
        }
        catch(SQLException e){
            if(logger.isDebugEnabled())
                logger.debug("Could not retrieve the 'isAutoIncrement'
property because not yet running on Java 1.5 - defaulting to NO. " +
                        "Table=" + tableName + ", Column=" +columnName, e);
            // Ignore this one here
        }

... what I think is happening is that Hibernate is not willing to ignore
the SQLException and that it is somehow detecting it or rethrowing it
rather than allowing the DBUnit try/catch to deal with it. Any ideas on how
to work around this?