views:

99

answers:

3

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));
+4  A: 

There is no difference, the add method returns this (for method chaining), not a new instance.

Pascal Thivent
+1  A: 

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()

Dave Aaron Smith
+1  A: 

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.

Ivan
just the answer i was looking for. thank you
Carlos Sanchez