1

I am using hibernate with a database wich is in a WAS (Websphere Application Server [IBM]) and I am getting this error sometimes:

java.lang.ArrayIndexOutOfBoundsException
            at com.ibm.ws.rsadapter.spi.CacheMap.removeLRU(CacheMap.java:378)
            at com.ibm.ws.rsadapter.spi.CacheMap.add(CacheMap.java:180)
            at com.ibm.ws.rsadapter.spi.WSRdbManagedConnectionImpl.cacheStatement(WSRdbManagedConnectionImpl.java:3150)
            at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.closeWrapper(WSJdbcPreparedStatement.java:513)
            at com.ibm.ws.rsadapter.jdbc.WSJccPreparedStatement.closeWrapper(WSJccPreparedStatement.java:290)
            at com.ibm.ws.rsadapter.jdbc.WSJdbcObject.close(WSJdbcObject.java:241)
            at com.ibm.ws.rsadapter.jdbc.WSJdbcObject.close(WSJdbcObject.java:194)
            at org.hibernate.jdbc.AbstractBatcher.closePreparedStatement(AbstractBatcher.java:563)
            at org.hibernate.jdbc.AbstractBatcher.closeStatement(AbstractBatcher.java:291)
            at org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:214)
            at org.hibernate.impl.SessionImpl.executeNativeUpdate(SessionImpl.java:1300)
            at org.hibernate.impl.SQLQueryImpl.executeUpdate(SQLQueryImpl.java:365)

Is a multithread application, so may be some stuff related with the cache of hibernate when multiple access are performed, but I am not sure about it. The error is thrown when the hibernate query sentence is executed like

query.list();

or

query.executeUpdate();

I have tried to set the cacheable to false and the CacheMode to IGNORE:

Session session = getSession();
session.setCacheMode(CacheMode.IGNORE);
session.createSQLQuery('query').setCacheable(false);

for disabling the cache, but the exceptions keep appearing, as I said, sometimes.

My hibernate-config.xml is this one:

<hibernate-configuration>
 <session-factory name="HibernateSessionFactory">
  <property name="hibernate.dialect">${hibernate.dialect}</property>
  <property name="hibernate.show_sql">${hibernate.show_sql}</property>
  <property name="hibernate.format_sql">${hibernate.format_sql}</property>
  <property name="hibernate.use_sql_comments">${hibernate.use_sql_comments}</property>
  <property name="hibernate.connection.autocommit">true</property>
  <property name="hibernate.connection.aggressive_release">false</property>
  <property name="hibernate.connection.release_mode">after_transaction</property>
  <property name="hibernate.cache.use_query_cache">false</property>
  <property name="hibernate.cache.use_second_level_cache">false</property>
  <property name="hibernate.connection.pool_size">0</property>
  <property name="hibernate.current_session_context_class">thread</property>
  <property name="hibernate.transaction.auto_close_session">true</property>
  <property name="hibernate.transaction.flush_before_completion">true</property>

  <!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
 </session-factory>
</hibernate-configuration>

Here you can see as I keep trying to totally disable the cache, but It still not work properly.

Any help or suggestion would be appreciated.

Thank you very much in advance! :D

Ragnar
  • 11
  • 3
  • 1
    This is not my area of expertise, but with my experience of working with application servers, I have noticed that eventhough hibernate does not cache the prepared statements, WAS does it. It first looks into its cache for same prepared statement before creating new one. If you are fine with decreased performance from DB, you can try disabling WAS caching of prepared statements. – NightsWatch Oct 08 '15 at 08:31
  • I have no problem about decrease the performance from DB this way, because I have another cache in the client. But I am not sure about disabling the cache in the WAS because I am not the owner of this server and It is hosting another applications apart from mine. – Ragnar Oct 08 '15 at 11:08
  • If your datasource is not shared between multiple applications then I think you should be able to set it to 0(or any value where WAS wont cache prepared statements) – NightsWatch Oct 08 '15 at 12:10
  • Ok, I have already tested it but It not work, is still the same :( – Ragnar Oct 08 '15 at 14:35
  • oh :( but now I am wondering how caching may happen once you disabled through your code as well as in WAS :S I will message here once I get something on my mind. – NightsWatch Oct 08 '15 at 15:01
  • Try synchronizing on the CacheMap if the container will let you w/out throwing a diff. error. Possibly you are getting concurrent access on it and it's throwing the index count off when the method gets run. But admittedly, this is a Hail Mary suggestion. BTW, this has come up before. See: http://ibm.software.websphere.application-server.narkive.com/VWgns7hA/arrayindexoutofboundsexception-at-com-ibm-ws-rsadapter-spi-cachemap – Matt Campbell Oct 08 '15 at 18:05

0 Answers0