I am having a problem with my Glassfish Web Application:
I use a persistence provider and EJB facedes on my glassfish application. the Mysql connection is configured as a JDBC resource.
The problem is when I update the database locally (using mysql promt or some other client), the glassfish server still “sees” the old values. I realize that there is probably some type of caching somewhere between the glassfis server and the Msyql DB. I am quite sure there is some parameter I can change to fix this, but after searching for quite some time I can’t seem to find it. Can anyone direct me to teh problematic region? the mysql JDBC drive? web.xml? connection pool?
Some technical details:
Database: Mysql 5.1
Server: Glassfish 3.1
Server is connecting to the db with root username
I use EclipseLink as persistence provider on the glassfish application
configuration (sun-resources.xml):
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="mysql_drivingschool_rootPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="serverName" value="localhost"/>
<property name="portNumber" value="3306"/>
<property name="databaseName" value="drivingschool"/>
<property name="User" value="*****"/>
<property name="Password" value="****"/>
<property name="URL" value="jdbc:mysql://localhost:3306/******"/>
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
</jdbc-connection-pool>
JPA uses a two-tier caching mechanism. The first level cache is the current PersistenceContext. The Level-2-cache is shared among different contexts.
You can control caching behavior. It is dependent on the JPA implementation you are using. Since you are on EclipseLink see this introduction. However this would degrade performance of your application.
Restarting the application (not the server) is what we do if we need to update the database manually. If it happens more often in production state, you should fetch the relevant data directly from the database.