【问题标题】:Is there any difference in performance between these two instructions?这两条指令在性能上有什么区别吗?
【发布时间】:2010-06-23 16:41:03
【问题描述】:

我有以下标准规范,想知道它们的性能或内存使用是否有任何差异。 第一种方式:

criteria.add(Restrictions.eq("case.estadoOperativo", Caso.EstadoOperativo.COMPLETADO))
        .add(Restrictions.eq("case.estadoAdministrativo", Caso.EstadoAdministrativo.TARIFICADO));

第二种方式:

criteria.add(Restrictions.eq("case.estadoOperativo", Caso.EstadoOperativo.COMPLETADO));
criteria.add(Restrictions.eq("case.estadoAdministrativo",Caso.EstadoAdministrativo.TARIFICADO));

【问题讨论】:

    标签: java hibernate orm criteria performance


    【解决方案1】:

    没有区别,add 方法返回this(用于方法链接),而不是新实例。

    【讨论】:

      【解决方案2】:

      简而言之,没有。编译后,criteria.add 和 .add 将在功能上变得相同。有一种可能,其中一个或另一个编译速度会稍快一些,但不同之处在于编译时间只有几纳秒,而在运行时没有差异。

      【讨论】:

        【解决方案3】:

        不。来自http://docs.jboss.org/hibernate/core/3.3/api/的api文档

        add(Criterion criterion)
            Add a restriction to constrain the results to be retrieved.
        

        您实际上还没有检索到任何结果。在您调用 .list() 之前,您的任何限制都不重要

        【讨论】:

          猜你喜欢
          • 2018-08-25
          • 2017-04-06
          • 1970-01-01
          • 2019-11-20
          • 2011-07-09
          • 1970-01-01
          • 2017-10-19
          • 1970-01-01
          相关资源
          最近更新 更多