How can I get the nextException from a SQLGrammarException?
I use Hibernate and want to store a record and get the following exception. (I know the meaning of SQL Error -301, but I cannot find the field which has a false datatype. So I need the getNextException to know which field is wrong.)
Code:
08:01:25,733 WARN [JDBCExceptionReporter] SQL Error: -99999, SQLState: null
08:01:25,733 ERROR [JDBCExceptionReporter] Non-atomic batch failure. The batch was submitted, but at least one exception occurred on an individual member of the batch. Use getNextException() to retrieve the exceptions for specific batched elements.
08:01:25,733 WARN [JDBCExceptionReporter] SQL Error: -301, SQLState: 07006
08:01:25,733 ERROR [JDBCExceptionReporter] Error for batch element #0: DB2 SQL error: SQLCODE: -301, SQLSTATE: 07006, SQLERRMC: 10
08:01:25,733 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
...
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
Caused by: org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2224)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:296)
... 149 more
Caused by: com.ibm.db2.jcc.a.ge: Non-atomic batch failure. The batch was submitted, but at least one exception occurred on an individual member of the batch. Use getNextException() to retrieve the exceptions for specific batched elements.
at com.ibm.db2.jcc.a.j.a(j.java:397)
at com.ibm.db2.jcc.a.id.b(id.java:2935)
at com.ibm.db2.jcc.a.id.a(id.java:2704)
at com.ibm.db2.jcc.a.id.executeBatch(id.java:2516)
at com.ibm.db2.jcc.a.id.executeBatch(id.java:1348)
at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:519)
Now, I want the to "Use getNextException() to retrieve the exceptions for specific batched elements". But this does not print the nextException to my console:
Code:
public void save()
{
try {
//save the record
}
catch (SQLGrammarException ex) {
while(ex != null) {
java.lang.System.out.println(ex.getSQLException().getNextException());
throw (SQLGrammarException) ex;
}
}
But this does not work. The same stacktrace without the "getNextException" occurs. But I need the getNextException to find out, what s wrong.
How can I get the getNextException()???