-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Restarting logic for database failures
PostPosted: Sat Nov 03, 2007 8:39 pm 
Newbie

Joined: Sat Nov 03, 2007 8:32 pm
Posts: 1
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>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.