2

休止状態でのこのエラーの問題の原因を教えてください。Android でのデータ同期に OpenMobster Cloud Server (MBaaS ツール) を使用しています。

2014-09-08 10:43:15,763 WARN  [org.hibernate.util.JDBCExceptionReporter] (Thread-14) SQL  Error: 0, SQLState: null
2014-09-08 10:43:15,763 ERROR [org.hibernate.util.JDBCExceptionReporter] (Thread-14)  failed batch
2014-09-08 10:43:15,764 ERROR [org.hibernate.event.def.AbstractFlushingEventListener]  (Thread-14) Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
 at  org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java :126)
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
   at   org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEven tListener.java:321)
   at  org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListe ner.java:64)
   at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:996)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1141)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
   at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:835)
   at  org.openmobster.core.synchronizer.server.engine.ServerSyncEngineImpl.getChangeLogEntry(Serve rSyncEngineImpl.java:576)
   at  org.openmobster.core.synchronizer.server.engine.ServerSyncEngineImpl.addChangeLogEntries(Ser verSyncEngineImpl.java:548)
   at  org.openmobster.core.synchronizer.event.SyncChannelEventListener.updateChangeLog(SyncChannel EventListener.java:126)
   at   org.openmobster.core.synchronizer.event.SyncChannelEventListener.channelUpdated(SyncChannelE ventListener.java:95)
   at  org.openmobster.core.services.CometService.broadcastChannelEvent(CometService.java:106)
   at  org.openmobster.core.services.MobileObjectMonitor.messageIncoming(MobileObjectMonitor.java:205)
   at  org.openmobster.core.common.bus.BusConsumer.sendBusListenerEvent(BusConsumer.java:184)
   at org.openmobster.core.common.bus.BusConsumer.consume(BusConsumer.java:120)
   at org.openmobster.core.common.bus.BusConsumer.run(BusConsumer.java:77)
   at java.lang.Thread.run(Thread.java:724)
   Caused by: java.sql.BatchUpdateException: failed batch
   at org.hsqldb.jdbc.jdbcStatement.executeBatch(Unknown Source)
   at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(Unknown Source)
   at  org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:774)
  at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
  at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
  ... 18 more
4

1 に答える 1

4

ここでの問題は、「GenericJDBCException: Could not execute JDBC batch update」です。指定されたステートメントを実行できなかった理由はわかりません。

1 つの解決策は、BatchUpdateException.getNextException を使用してバッチ例外の理由を取得することです。ただし、jdbc ドライバーが null をサポートしていないなどの理由で、これが単に null を返す場合があります。そのため、代替の解決策は、バッチ更新の失敗の理由に関する情報が得られない場合です。休止状態がバッチ処理されないようにする方法を見つける必要があります。これは、たとえばテストケースのような隔離された環境で実行する場合に役立ちます。

これは、システム プロパティに以下を追加することで実現できます。

-Dhibernate.statement_cache.size=0 
-Dhibernate.jdbc.batch_size=0 
-Dhibernate.jdbc.use_scrollable_resultset=false
-Dhibernate.bytecode.use_reflection_optimizer=false
-Dhibernate.show_sql=true

これを実現する別の方法は次のとおりです。実行戦略を変更するために、hibernate は org.hibernate.jdbc.BatcherFactory の実装を受け入れる hibernate.jdbc.factory_class 設定プロパティを提供します。Hibernate はすでに NonBatchingBatcherFactory を提供しています。これは、このケースで必要なものです。適切な休止状態の構成は次のようになります。

final Configuration config = new Configuration();
// ... more config here
config.setProperty( "hibernate.jdbc.factory_class", "org.hibernate.jdbc.NonBatchingBatcherFactory" );

上記の BatchUpdateException を生成したコードは、簡単に追跡できる実際の例外になります。個々の SQL 例外を確認するために、テスト実行のためにバッチャー戦略を 1 回変更すると便利です。ただし、運用設定が異なる場合は、すべてのテストまたは継続的インテグレーションの戦略を変更しないでください。

参照:

  1. http://www.eishay.com/2010/04/testing-with-hibernate.html

  2. http://inoio.de/blog/2012/11/16/how-to-get-rid-of-hibernate-genericjdbcexception/

于 2014-09-11T05:29:27.060 に答える