-->
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.  [ 3 posts ] 
Author Message
 Post subject: resetting server settings again and again
PostPosted: Thu Sep 15, 2005 9:56 am 
Newbie

Joined: Tue Jul 26, 2005 1:25 pm
Posts: 14
We ran a trace on our application, and it looks as if it continually resets the server settings - isolation level, max precision, implicit transactions, quoted identifier, etc. It seems to do it for every connection as well as when it's just idle.

Is this something Hibernate is doing, or could it possibly be my c3p0 connection pool? Either way, I was wondering if anyone knows how to set up the connection settings just once and use them from there on out.
Thank you so much -
S


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 12:23 pm 
Senior
Senior

Joined: Tue Feb 08, 2005 5:26 pm
Posts: 157
Location: Montréal, Québec - Canada
How are you getting the connection?

Maybe you are executing the following code constantly:
new Configuration().configure();
configuration.buildSessionFactory();
factory.createSession()


Just in case, make sure that these lines are only executed once at application startup
new Configuration().configure();
configuration.buildSessionFactory();

Hope that helps...

_________________
Vincent Giguère
J2EE Developer


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 4:09 pm 
Newbie

Joined: Tue Jul 26, 2005 1:25 pm
Posts: 14
Thanks for your response - we are using pretty default HibernateUtil methods to set up the connections. I just call the static methods to get session and all that. If calling configuration.configure(document) is the only way I can be calling and recalling these server settings it definitely does narrow things down.

Thank you,
s

Code:
public class HibernateUtil {

    private static final Log LOG = LogFactory.getLog(HibernateUtil.class);
   private static final SessionFactory sessionFactory;
   private static final ThreadLocal threadSession = new ThreadLocal();
   private static final ThreadLocal threadTransaction = new ThreadLocal();
   
   static{
      try{         
         DocumentBuilderFactory fct = DocumentBuilderFactory.newInstance();
         DocumentBuilder docBuilder = fct.newDocumentBuilder();
         Document doc = docBuilder.parse("hibernate.cfg.xml");
         Configuration cfg = new Configuration();
         cfg.configure(doc);
         sessionFactory = cfg.buildSessionFactory();
      }catch (Throwable ex){
         LOG.error(ex);
         throw new ExceptionInInitializerError(ex);
      }
      
   }
   
   public static Session getSession()throws XOpsException{
      Session s = (Session)threadSession.get();
      try{
         if(s == null){
            s = sessionFactory.openSession();
            threadSession.set(s);
         }
      }catch(HibernateException ex){
         LOG.error(ex);
         throw new XOpsException(ex);
      }
      return s;
   }
   
   public static void closeSession()throws XOpsException{
      try{
         Session s = (Session)threadSession.get();
         threadSession.set(null);
         if(s != null && s.isOpen()){
            s.close();
         }
      }catch(HibernateException ex){
            LOG.error(ex);
            throw new XOpsException(ex);
      }
   }
   
   
   
   public static void beginTransaction()throws XOpsException{
      Transaction tx = (Transaction) threadTransaction.get();
      try{
         if(tx == null){
            tx = getSession().beginTransaction();
            threadTransaction.set(tx);
         }
      }catch(HibernateException ex){
         LOG.error(ex);
         throw new XOpsException(ex);
      }
   }
   
   public static void commitTransaction()throws XOpsException{
      Transaction tx = (Transaction)threadTransaction.get();
      try{
         if(tx != null && !tx.wasCommitted()&& !tx.wasRolledBack()){
            tx.commit();
         }
         threadTransaction.set(null);
      }catch(HibernateException ex){
         rollbackTransaction();
         LOG.error(ex);
         throw new XOpsException(ex);
      }
   }
   
   public static void rollbackTransaction() throws XOpsException{
      Transaction tx = (Transaction)threadTransaction.get();
      try{
         threadTransaction.set(null);
         if(tx != null && !tx.wasCommitted() && !tx.wasRolledBack()){
            tx.rollback();
         }
      }catch(HibernateException ex){
         LOG.error(ex);
         throw new XOpsException(ex);
      }finally{
         closeSession();
      }
   }
}


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

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.