Hi guys,
I have a situation where I have a periodic problem with Hibernate in a web app.
I am using Hibernate 3.2.5, Tomcat 5.5.25, MySql 5.0.45 and JDK1.5.0_11.
I am updating a record in a request, and I can see, via SQLyog that the transaction has committed.
Another request retrieves the record from the db, but Hibernate (HQL) is retrieving the record with the values prior to the update. It does this once in about 10, which is nearly worse than all the time.
It appears like it is reading the record from a cache, but my understanding of Hibernate caching is poor/absent.
Any pointers?
Code:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- dialect for MySQL -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://myserver:3306/myDb?autoReconect=true</property>
<property name="hibernate.connection.username">myApp</property>
<property name="hibernate.connection.password">myApp</property>
<!-- Use the C3P0 connection pool. -->
<property name="c3p0.acquire_increment">1</property>
<property name="c3p0.idle_test_period">100</property> <!-- seconds -->
<property name="c3p0.min_size">10</property>
<property name="c3p0.max_size">100</property>
<property name="c3p0.max_statements">0</property>
<property name="c3p0.timeout">1800</property> <!-- seconds -->
<!-- Time a Connection should be permitted to go unused before being culled from the pool -->
<property name="c3p0.maxIdleTime">21600</property> <!-- seconds -->
<!-- Time after which we force the pool to cull any Connections acquired from the database -->
<property name="c3p0.maxConnectionAge">21600</property> <!-- seconds -->
<!--
Nominated table name for connection testing. Using the name provided, c3p0
will create an empty table, and make a simple query against it to test the
database
-->
<property name="c3p0.automaticTestTable">c3p0_conn_test</property> <!-- seconds -->
<property name="c3p0.idleConnectionTestPeriod">10800</property> <!-- seconds -->
<!-- Disable second-level cache. -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="cache.use_query_cache">false</property>
<property name="cache.use_minimal_puts">false</property>
<property name="max_fetch_depth">3</property>
<!-- Print SQL to stdout. -->
<property name="show_sql">false</property>
<property name="format_sql">false</property>
<!-- Bind the getCurrentSession() method to the thread. -->
<property name="current_session_context_class">thread</property>
<property name="hibernate.transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<!-- Hibernate XML mapping files -->
<mapping resource="SystemParameters.hbm.xml" />
</session-factory>
</hibernate-configuration>
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="com.taylodge.library.data">
<class
name="SystemParameters"
table="system_parameters"
>
<meta attribute="sync-DAO">false</meta>
<id
name="id"
type="integer"
column="id"
>
<generator class="increment"/>
</id>
<property
name="sessionTimeoutMins"
column="session_timeout_mins"
type="integer"
not-null="true"
length="10"
/>
<property
name="monitorSleepMins"
column="monitor_sleep_mins"
type="integer"
not-null="true"
length="10"
/>
<property
name="smtpServer"
column="SMTP_server"
type="string"
not-null="false"
length="100"
/>
<property
name="fromEmailAddress"
column="from_email_address"
type="string"
not-null="false"
length="100"
/>
<many-to-one
name="defaultWriteOffReason"
column="default_write_off_reason_id"
class="WriteOffReason"
not-null="true"
>
</many-to-one>
</class>
</hibernate-mapping>