Hibernate's Query class has setters for any type of primitive parameter such as setString setBoolean setLong etc, but it also has a setParameter method which receives an Object and can replace all other setters.
Since they are not deprecated, is there any advantage to using specific type parameters in terms of performance?
Should setParameter be used only with custom Objects?
based on cursory read of the implementation of the Query class in here.
is there any advantage to using specific type parameters in terms of performance?
Yeah, as if you directly call the setParameter function, the hibernate will need to "guess" the type of the object. But, It looks like that those method (setString, setBoolean, etc) just a convenient method to set a parameter. Because, in the end, these function will call function setParamater(int,Object,Type). Which is, the same with the setParameter function.
Should
setParameterbe used only with custom Objects?
Not necessary. I mean, you still be able to use an Integer or the other wrapper class (Boolean, Float, etc). It just that, there is additional operation that hibernate needs to do to check what type the value is and handle it properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With