1 Reply Latest reply on Mar 22, 2011 3:58 AM by tawalisa

    Strange issue using hibernate

    tawalisa

      Hi all,

                I use below code to test our Teiid .  Our vdb have 2 datasouce , And thay are XA. Our xa transaction time out is 300 second.

       

           1. I declare an session through sessionfactory.openSession().

           2. I use this session do a "select" command.

           3. Than I close session.

           4. sleep 200 second.

           5. I declare an session through sessionfactory.openSession() again. I use same sessionfactory.

           6. sleep 150 second. At this time, running this of program has spent 350. It is over "xa transaction time out" (300 second)

           7, When do a "select" command . it will throw an exception.

      Caused by: Transaction is not active: tx=TransactionImple < ac, BasicAction: 10105ce2:9195:4d821f41:5fe4 status: ActionStatus.ABORTED >

       

           Does sessionfactory.openSession() have cache?

           Or I am wrong with my code.

           If I am wrong,please correct me.

       

           If I use jdbc to create connection, I can not find any question.

       

       

       

              ///////////////////  code ///////////////////////////////////

              Configuration cfg = initConfig();

              addResources(cfg);

       

              SessionFactory sessionfactory = cfg.buildSessionFactory();

       

              Transaction tx = null;

       

              try{           

                  for (int i = 0; i < 2; i++) {

                      Session session = sessionfactory.openSession();

                      tx = session.beginTransaction();

       

                      String entityName = "test.MobType";

                      List results = session.createCriteria(entityName)

                              .setMaxResults(1).list();

                      System.out.println("======1234");

                      if (i > 0) {

                          Thread.sleep(100 * 1000);

                      }

                      System.out.println("======1234567");

                      results = session.createCriteria(entityName).setMaxResults(1)

                              .list();

       

                      tx.commit();

                      session.close();

                      System.out.println("begin sleep no commit;");

                      Thread.sleep(250 * 1000);

                      System.out.println("end sleep");

                  }

       

              }catch(Exception e){

                  tx.rollback();

                  e.printStackTrace();

              }

       

              }

        • 1. Strange issue using hibernate
          tawalisa

          Hi all,

                   

                    If I set hibernate connection pool size to 0, it will be ok.  But I don't think this the best solution. Maybe it is an issue for teiid jdbc driver or hibernate dialect.

           

           

               Thanks

          Best Regards

          Allen