简体   繁体   中英

Is there any difference in performance between these two instructions?

i have the following criteria specification and wanted to know if there is any difference in the performance or the memory usage of them. 1st way:

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

2nd way:

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

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

Nope. From the api documentation at http://docs.jboss.org/hibernate/core/3.3/api/

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

You haven't actually retrieved any results yet. None of your restrictions will matter until you call .list()

In short, no. After compilation, criteria.add and .add will become functionally identical. There's a possibility that one or the other will be slightly faster to compile, but the difference would be that of a few nanoseconds of compile time and no differences at runtime.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM