-->
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.  [ 7 posts ] 
Author Message
 Post subject: Slow beginTransaction()
PostPosted: Mon Nov 28, 2005 10:24 am 
Newbie

Joined: Mon Nov 28, 2005 10:09 am
Posts: 11
Hi,
These lines are repeated in two places in my project :

Code:
            session = HibernateUtil.getSessionFactory().openSession();
            tx = session.beginTransaction();


As you know, they are using HibernateUtil class, which is downloadable from hibernate web site as an example. (It's the latest version).
One on these lines executes very fast, and the other one, very slowly! What could cause this?

Hibernate version: 3.0

Mapping documents:

Code between sessionFactory.openSession() and session.close():
Code:
        try
        {
            session = HibernateUtil.getSessionFactory().openSession();
            tx = session.beginTransaction();
            Query q = session.createQuery("select o from WindowTO as o where id=" + dto.getId() + " and deleted=0");
         
            List objects = q.list();
            //assert(objects.size() <= 1);
            Iterator iter = objects.iterator();
            WindowTO cur = null;
            while (iter.hasNext())
            {
                cur = (WindowTO) iter.next();
                cur.setKeypad_address(dto.getKeypad_address());
                cur.setLed_address(dto.getLed_address());
                cur.setActive(dto.getActive());
                cur.setCode(dto.getCode());
                cur.setTitle(dto.getTitle());
                cur.setDeleted(dto.getDeleted());
                cur.setIsSoftware(dto.getIsSoftware());
                session.save(cur);
                break;
            }

            tx.commit();
            session.close();

AND
Code:
        try
        {
            session = HibernateUtil.getSessionFactory().openSession();
            tx = session.beginTransaction();
            Query q = session.createQuery("select o from QueueTO as o where id=" + dto.getId() + " and deleted=0");
         
            List objects = q.list();
            //assert(objects.size() <= 1);
            Iterator iter = objects.iterator();
            QueueTO cur = null;
            while (iter.hasNext())
            {
                cur = (QueueTO) iter.next();
                cur.setName(dto.getName());
                cur.setRank(dto.getRank());
                cur.setDeleted(dto.getDeleted());
                session.save(cur);
                break;
            }

            tx.commit();
            session.close();
        }



Full stack trace of any exception that occurs:

Name and version of the database you are using: Oracle 10g

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 11:10 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
you have more rows in one form tow tables


Top
 Profile  
 
 Post subject: One of them always take a new JDBC Connection
PostPosted: Mon Nov 28, 2005 11:27 am 
Newbie

Joined: Mon Nov 28, 2005 10:09 am
Posts: 11
After debugging into hibernate code, I understand that the reason is that the slow one always takes a new connection. But the other one gets a connection from connection pool.
But there is no different between them! Just two java files! I can not understand why one on them doesn't use connection pool!

Thanks
<Farshid/>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 11:35 am 
Newbie

Joined: Mon Nov 28, 2005 10:09 am
Posts: 11
in DriverManagerConnectionProvider.java, we have below lines:
Code:
   public Connection getConnection() throws SQLException {

      if ( log.isTraceEnabled() ) log.trace( "total checked-out connections: " + checkedOut );

      synchronized (pool) {
         if ( !pool.isEmpty() ) {
            int last = pool.size() - 1;
            if ( log.isTraceEnabled() ) {
               log.trace("using pooled JDBC connection, pool size: " + last);
               checkedOut++;
            }
            Connection pooled = (Connection) pool.remove(last);
            if (isolation!=null) pooled.setTransactionIsolation( isolation.intValue() );
            if ( pooled.getAutoCommit()!=autocommit ) pooled.setAutoCommit(autocommit);
            return pooled;
         }
      }

      log.debug("opening new JDBC connection");
      Connection conn = DriverManager.getConnection(url, connectionProps);
      if (isolation!=null) conn.setTransactionIsolation( isolation.intValue() );
      if ( conn.getAutoCommit() ) conn.setAutoCommit(false);

      if ( log.isDebugEnabled() ) {
         log.debug( "created connection to: " + url + ", Isolation Level: " + conn.getTransactionIsolation() );
      }
      if ( log.isTraceEnabled() ) checkedOut++;

      return conn;
   }



When calling one of the beginTransactions(), the pool size is every time 0, but in other transactions, it's always 1.
Any suggestion?
Please Help Me!

<Farshid/>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 11:47 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
try "<max-connections>4</max-connections>" in configuration file


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 11:57 am 
Newbie

Joined: Mon Nov 28, 2005 10:09 am
Posts: 11
The configuration file contains
Code:
<property name="hibernate.connection.pool_size">10</property>


Is it enough or I should add the above line too?

<Farshid/>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 1:00 pm 
Newbie

Joined: Mon Nov 28, 2005 10:09 am
Posts: 11
Any idea about this problem? What cause my connection pool to be empty sometimes?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.