JPA查询ObjectDB的性能问题

时间:2014-01-15 18:30:00

标签: performance jpa objectdb

我们在ObjectDB中的查询性能存在很大问题,这是我们的代码。任何帮助将不胜感激。

查询的第一个版本为数据库中的前40个记录提供50毫秒的结果,但查询40多个记录的第二个版本提供19秒。我们指出,从他的53个记录表现显着下降。在其他查询上,阈值是不同的,可能是由于结果的大小(可能与相关对象的数量有关)

第一版代码。

EntityManagerFactory emf =                         Persistence.createEntityManagerFactory( “objectdb://10.10.10.14/E_POLICIJA.odb;用户=管理员;密码=管理员”); // $ NON-NLS-1 $

           em = emf.createEntityManager();


         long startTime;
         long endTime;

         startTime = System.currentTimeMillis();

          int i = 0;
          while(i < 40){
              TypedQuery<AktImpl> queryAkt =
                  em.createQuery("SELECT e FROM AktImpl e", AktImpl.class);

              queryAkt.setFirstResult(i);
              queryAkt.setMaxResults(20);
              queryAkt.getResultList();
              i += 20; 
          }

          endTime = System.currentTimeMillis();
        System.out.println((endTime - startTime));
    }

第二版代码

           EntityManagerFactory emf =
                    Persistence.createEntityManagerFactory("objectdb://10.10.10.14/E_POLICIJA.odb;user=admin;password=admin"); //$NON-NLS-1$

           em = emf.createEntityManager();


         long startTime;
         long endTime;

         startTime = System.currentTimeMillis();

          int i = 0;
          while(i < 60){
              TypedQuery<AktImpl> queryAkt =
                  em.createQuery("SELECT e FROM AktImpl e", AktImpl.class);

              queryAkt.setFirstResult(i);
              queryAkt.setMaxResults(20);
              queryAkt.getResultList();
              i += 20; 
          }

          endTime = System.currentTimeMillis();
        System.out.println((endTime - startTime));
    }

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

发现问题是在该特定应用程序中定义的循环渴望关系,该关系需要以查询结果递归地加载许多对象。

解决方案是将关系设置从急切变为懒惰。

更多详细信息,请参阅this forum thread

相关问题