0 Replies Latest reply on Apr 29, 2009 10:50 PM by heilien

    problem in concurrent access of database

      good day all,

      I am running 2 program on separate JVM on the same server. both use hibernate to access the database. It seems that program1 always wait for program2 's database access complete and continue, or vice versa. It looks like sequential execution.

      I guess it's something wrong with my code. anyone can help me with it?

      below is the hibernate util class
      import org.hibernate.*;
      import org.hibernate.cfg.*;

      public class HibernateUtil {

      private static SessionFactory sessionFactory;
      
       static {
       try {
       sessionFactory = new Configuration().configure().buildSessionFactory();
       } catch (Throwable ex) {
       throw new RuntimeException (ex);
       }
       }
      
       public static SessionFactory getSessionFactory() {
       return sessionFactory;
       }
      
      }



      every method i access the database i will use the following pattern to get session and commit

      public static ArticleType createArticleType(String description) {
       ArticleType ArticleType = new ArticleType();
       ArticleType.setDescription(description);
       Session session = HibernateUtil.getSessionFactory().getCurrentSession();
       session.beginTransaction();
       session.save(ArticleType);
       session.getTransaction().commit();
       return ArticleType;
       }



      I am wondering should I open and close session for every call to the database, to prevent the blocking of other process.

      thanks in advance