Hi,
I've set up a tomcat6 server with a JNDI datasource, and I wish to use this datasource through Hibernate.
I had several problems, with my setup, only one strange issue remained that I can not seem to solve:
After modifying a piece of data, it is saved to the database correctly, but when this data gets displayed sometimes the new, sometimes the old value gets displayed.
Currently to keep it simple, the JNDI datasource (or DBCP) is configured to have a maximum of 1 alive connection , and no Idle connections, so there should be only one connection opened for a limited of time. (These values will be increased, when the problem is solved).
This resource is configured in GlobalNamingResources, and made available for all web applications through context.xml.
Code:
<Resource name="jdbc/myDB" type="javax.sql.DataSource" auth="Container".
maxActive="1"
maxIdle="0"
removeAbandoned="true"
removeAbandonedTimeout="30"
logAbandoned="true"
connectionProperties="useUnicode=true;characterEncoding=UTF-8;connectionCollation=utf8_general_ci;characterSetResults=utf8"
username="xxxxxxxxxxxxxxxx"
password="xxxxxxxxxxxxxxxx"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/myDatabase"
/>
This is the spring configuration snipet, that is responsible for initalizing Hibernate. I wanted DBCP to manage database connections, so I set the property hibernate.connection.release_mode to after_transaction.
Code:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/myDB"/>
<property name="resourceRef" value="true" />
</bean>
<!-- Set up hibernate's AnnotationSessionFactory: list annotated classes, and define hibernate additional settings -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<set>
<value>com.greg.Person</value>
</set>
</property>
<property name="hibernateProperties">
<props>
<prop key="connection.useUnicode">true</prop>
<prop key="connection.characterEncoding">utf-8</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.connection.datasource">java:comp/env/jdbc/sunforgeDB</prop>
<prop key="hibernate.connection.release_mode">after_transaction</prop>
<prop key="cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
</props>
</property>
</bean>
<!-- Set up hibernate's transaction manager -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
Currently my best guess that there is somekind of chaching mechanism, that I failed to turn off.
Can anybody shed some light on this problem?
Thanks,
Greg