I'm trying to make my hibernate application robust and have it handle the database service temporarily being down. I am puzzled by the behavior that a simple program has.
First, the setup: Hibernate 3.2.5 with MS Sql Server and the Microsoft JDBC drivers, all running under Linux.
Here is my little sample java program:
Code:
public class Hibernate {
public static void main(String[] args) throws Exception {
SessionFactory fact = new Configuration().configure().buildSessionFactory();
Session sess = null;
while (true) {
try {
sess = fact.openSession();
PObj o = (PObj)sess.get(PObj.class, new Long(1));
System.out.println(o.getValue());
sess.close();
Thread.sleep(2000);
} catch (HibernateException e) {
System.out.println(e.getMessage());
Thread.sleep(2000);
}
}
}
}
The idea should be clear - if I get a failure, wait a little bit and retry. The odd behavior I get is that the program works fine, reading PObj out of the database on each loop. If the database is suspended, oddly, I do not get any exception at all. The sess.get(..) call returns the last value of PObj that was read from the database, without any clue that it is actual a stale value, and that the database is down.
I'm very confused. What am I doing wrong?
Here is the hibernate configuration that I'm using:
Code:
<hibernate-configuration>
<session-factory>
<!-- properties -->
<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="connection.url">...</property>
<property name="hibernate.connection.database">...</property>
<property name="hibernate.connection.username">...</property>
<property name="hibernate.connection.password">...</property>
<property name="show_sql">false</property>
<property name="hibernate.c3po.max_size">5</property>
<property name="hibernate.c3po.min_size">0</property>
<property name="hibernate.c3po.timeout">5000</property>
<property name="hibernate.c3po.max_statements">100</property>
<property name="hibernate.c3po.idle_test_period">300</property>
<property name="hibernate.c3po.acquire_increment">2</property>
<!-- mappings -->
<mapping resource="com/siegel/examples/PObj.hbm.xml"/>
</session-factory>
</hibernate-configuration>