Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8564607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:14:17+00:00 2026-06-11T17:14:17+00:00

I am using Hibernate 3 in my development and WAS Liberty Profile as my

  • 0

I am using Hibernate 3 in my development and WAS Liberty Profile as my local development server. I am trying to create an exception handling when DB server was down. To do this, I am trying simulate the environment by connecting to a fake IP address in hibernate.cfg.xml for this testing.

I have the following JAVA code but the exception wasn’t catch in the exception code when DB connection wasn’t ready. The console output shows the connection could not be obtain as warning. May I know how could I capture my scenario in exception code instead of showing it as a warning?

JAVA code

   public class HibernateUtil { 
     static {
       try {
         log.info("HibernateUtil.static - Begin");

         if (cacheFactory.get("Factory") == null) {
           sessionFactory = new Configuration().configure().buildSessionFactory();
           cacheFactory.put("Factory", sessionFactory);
         } else {
           sessionFactory = (SessionFactory) cacheFactory.get("Factory");
         }

         log.info("HibernateUtil.static - end");

       } catch (HibernateException ex) {
         throw new RuntimeException("[Exception] : " + ex.getMessage(), ex);
       }
     }

     ...
     ...
   }

Console output

INFO  2012-09-20 15:24:16,314 [HibernateUtil.java:37] - HibernateUtil.static - Begin

[WARNING ] recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
[WARNING ] Property [hibernate.cglib.use_reflection_optimizer] has been renamed to [hibernate.bytecode.use_reflection_optimizer]; update your properties appropriately
[WARNING ] recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
[WARNING ] Property [hibernate.cglib.use_reflection_optimizer] has been renamed to [hibernate.bytecode.use_reflection_optimizer]; update your properties appropriately
[WARNING ] Could not obtain connection to query metadata

INFO  2012-09-20 15:24:24,001 [HibernateUtil.java:46] - HibernateUtil.static - end

Hibernate configuration

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.connection.url">jdbc:db2://192.168.1.6:51201/MYDB</property>
    <property name="hibernate.connection.username">myuser</property>
    <property name="hibernate.connection.password">MyPassword</property>

    <property name="hibernate.connection.driver_class">com.ibm.db2.jcc.DB2Driver</property>
    <property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
    <property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
    <property name="hibernate.jdbc.batch_size">100</property>
    <property name="hibernate.show_sql">false</property>

    <property name="hibernate.connection.release_mode">auto</property>
    <property name="current_session_context_class">thread</property>
    <property name="hibernate.connection.autocommit">true</property>
    <property name="hibernate.transaction.flush_before_completion">true</property>
    <property name="hibernate.transaction.auto_close_session">false</property>
    <property name="hibernate.cglib.use_reflection_optimizer">true</property>

    ...

    </session-factory>
</hibernate-configuration>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:14:18+00:00Added an answer on June 11, 2026 at 5:14 pm

    I think what you need is test-on-connection-acquire

    Seems you are using the default Hibernate connection pool. Unfortunately, hibernate connection pool does not support his property and they recommend third party connection pool libraries like C3P0.

    The official documentation of Hibernate discourages using their default connection.

    Hibernate’s own connection pooling algorithm is, however, quite
    rudimentary. It is intended to help you get started and is not
    intended for use in a production system, or even for performance
    testing. You should use a third party pool for best performance and
    stability.

    Here is how you can configure C3P0 with hibernate. Here are relevant properties of C3P0 for testing connections.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I'm starting a new web development project with my team using Hibernate and
I've been using the following web development stack for a few years: java/spring/hibernate/mysql/jetty/wicket/jquery For
I'm currently developing a Wicket Spring Hibernate application. For development I'm using Jetty as
I'm using JPA (Hibernate as provider), Glassfish and MySQL. Everything works great in development,
I am using the create-drop option for development, when deploying to mysql database (using
Using hibernate, how can I persist a class with a List<String> field? Consider the
When using hibernate to retrieve data from Oracle 11g DB using either org.hibernate.dialect.Oracle10gDialect or
when using hibernate with spring, can someone explain how the session unit of work
When using Hibernate 2nd level cache and query cache and not specifying anything inside
I am using Hibernate 3 . Hi , I am attending a session on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.