org.hibernate.exception.GenericJDBCException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • For all empty but not-null CLOBs MySQL drivers do the following (com.mysql.jdbc.PreparedStatement): String forcedEncoding = this.connection.getClobCharacterEncoding(); if (forcedEncoding == null) { setString(i, x.getSubString(1L, (int) x.length())); } else { try { setBytes(i, x.getSubString(1L, (int)x.length()).getBytes(forcedEncoding)); } catch (UnsupportedEncodingException uee) { throw SQLError.createSQLException("Unsupported character encoding " + forcedEncoding, SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor()); } } As you can see, getSubString is called with first argument (start) equal to 1, even if length of CLOB is 0. Of course, it's not very good, but it worked for previous versions of Hibernate. But in 3.6.0 getSubString() handling in ClobProxy introduces additional checks that prevents the code above from working: if ( start > getLength() ) { throw new SQLException( "Start position [" + start + "] cannot exceed overall CLOB length [" + getLength() + "]" ); } Thus this code will now thrown an exception if content is empty (but not null!) CLOB. Here the part of stack trace: 31.10 16:46:03 .AbstractFlushingEventListener ERROR Could not synchronize database state with session org.hibernate.exception.GenericJDBCException: could not insert: [ru.arptek.classes.dummy.Article$Content] 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.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2436) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2856) at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216) at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:795) at ru.arptek.arpsite.content.WebObjectHome.create(WebObjectHome.java:122) (...) Caused by: java.sql.SQLException: Start position [1] cannot exceed overall CLOB length [0] at org.hibernate.engine.jdbc.ClobProxy.invoke(ClobProxy.java:146) at $Proxy52.getSubString(Unknown Source) at com.mysql.jdbc.PreparedStatement.setClob(PreparedStatement.java:3542) at com.mysql.jdbc.jdbc2.optional.PreparedStatementWrapper.setClob(PreparedStatementWrapper.java:299) at org.apache.commons.dbcp.DelegatingPreparedStatement.setClob(DelegatingPreparedStatement.java:187) at org.apache.commons.dbcp.DelegatingPreparedStatement.setClob(DelegatingPreparedStatement.java:187) at org.hibernate.type.descriptor.sql.ClobTypeDescriptor$1.doBind(ClobTypeDescriptor.java:60) at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:89) at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:282) at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:277) at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:85) at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2166) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2412) ... 70 more I believe there should be additional check like: long start = (Long) args[0]; if ( start < 1 ) { throw new SQLException( "Start position 1-based; must be 1 or more." ); } int length = (Integer) args[1]; if ( length < 0 ) { throw new SQLException( "Length must be great-than-or-equal to zero." ); } // workaround for MySQL incompatibility if ( start == 1 && length == 0) { return ""; } else if ( start > getLength() ) { throw new SQLException( "Start position [" + start + "] cannot exceed overall CLOB length [" + getLength() + "]" ); } return getSubString( start-1, length );
    via by Sergey Vladimirov,
  • For all empty but not-null CLOBs MySQL drivers do the following (com.mysql.jdbc.PreparedStatement): String forcedEncoding = this.connection.getClobCharacterEncoding(); if (forcedEncoding == null) { setString(i, x.getSubString(1L, (int) x.length())); } else { try { setBytes(i, x.getSubString(1L, (int)x.length()).getBytes(forcedEncoding)); } catch (UnsupportedEncodingException uee) { throw SQLError.createSQLException("Unsupported character encoding " + forcedEncoding, SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor()); } } As you can see, getSubString is called with first argument (start) equal to 1, even if length of CLOB is 0. Of course, it's not very good, but it worked for previous versions of Hibernate. But in 3.6.0 getSubString() handling in ClobProxy introduces additional checks that prevents the code above from working: if ( start > getLength() ) { throw new SQLException( "Start position [" + start + "] cannot exceed overall CLOB length [" + getLength() + "]" ); } Thus this code will now thrown an exception if content is empty (but not null!) CLOB. Here the part of stack trace: 31.10 16:46:03 .AbstractFlushingEventListener ERROR Could not synchronize database state with session org.hibernate.exception.GenericJDBCException: could not insert: [ru.arptek.classes.dummy.Article$Content] 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.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2436) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2856) at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216) at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:795) at ru.arptek.arpsite.content.WebObjectHome.create(WebObjectHome.java:122) (...) Caused by: java.sql.SQLException: Start position [1] cannot exceed overall CLOB length [0] at org.hibernate.engine.jdbc.ClobProxy.invoke(ClobProxy.java:146) at $Proxy52.getSubString(Unknown Source) at com.mysql.jdbc.PreparedStatement.setClob(PreparedStatement.java:3542) at com.mysql.jdbc.jdbc2.optional.PreparedStatementWrapper.setClob(PreparedStatementWrapper.java:299) at org.apache.commons.dbcp.DelegatingPreparedStatement.setClob(DelegatingPreparedStatement.java:187) at org.apache.commons.dbcp.DelegatingPreparedStatement.setClob(DelegatingPreparedStatement.java:187) at org.hibernate.type.descriptor.sql.ClobTypeDescriptor$1.doBind(ClobTypeDescriptor.java:60) at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:89) at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:282) at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:277) at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:85) at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2166) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2412) ... 70 more I believe there should be additional check like: long start = (Long) args[0]; if ( start < 1 ) { throw new SQLException( "Start position 1-based; must be 1 or more." ); } int length = (Integer) args[1]; if ( length < 0 ) { throw new SQLException( "Length must be great-than-or-equal to zero." ); } // workaround for MySQL incompatibility if ( start == 1 && length == 0) { return ""; } else if ( start > getLength() ) { throw new SQLException( "Start position [" + start + "] cannot exceed overall CLOB length [" + getLength() + "]" ); } return getSubString( start-1, length );
    via by Sergey Vladimirov,
    • org.hibernate.exception.GenericJDBCException: could not insert: \[org.openxava.pruebas.modelo.CompA\] 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.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2267) 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.openxava.model.impl.HibernatePersistenceProvider.flush(HibernatePersistenceProvider.java:63) at org.openxava.model.impl.HibernatePersistenceProvider.commit(HibernatePersistenceProvider.java:48) at org.openxava.model.impl.MapFacadeBean.create(MapFacadeBean.java:41) at org.openxava.model.MapFacade.create(MapFacade.java:78) at org.openxava.actions.SaveAction.execute(SaveAction.java:27) at org.openxava.controller.ModuleManager.executeAction(ModuleManager.java:328) at org.openxava.controller.ModuleManager.executeAction(ModuleManager.java:257) at org.openxava.controller.ModuleManager.execute(ModuleManager.java:224)

    Users with the same issue

    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    esaar
    4 times, last one,
    17 more bugmates