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.
Hibernate的Query类具有任何类型的原始参数的setter,例如setString setBoolean setLong等,但它也有一个setParameter方法,它接收一个Object并可以替换所有其他setter。
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?
由于它们不被弃用,在性能方面使用特定类型参数是否有任何优势? setParameter应该只用于自定义对象吗?
1 个解决方案
#1
5
based on cursory read of the implementation of the Query
class in here.
基于粗略读取这里的Query类的实现。
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.
是的,就像你直接调用setParameter函数一样,hibernate将需要“猜测”对象的类型。但是,看起来那些方法(setString,setBoolean等)只是一个设置参数的方便方法。因为,最后,这些函数将调用函数setParamater(int,Object,Type)。也就是说,与setParameter函数相同。
Should
setParameter
be used only with custom Objects?setParameter应该只用于自定义对象吗?
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.
不必要。我的意思是,你仍然可以使用Integer或其他包装类(Boolean,Float等)。就是这样,hibernate需要做一些额外的操作来检查值是什么类型并正确处理它。
#1
5
based on cursory read of the implementation of the Query
class in here.
基于粗略读取这里的Query类的实现。
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.
是的,就像你直接调用setParameter函数一样,hibernate将需要“猜测”对象的类型。但是,看起来那些方法(setString,setBoolean等)只是一个设置参数的方便方法。因为,最后,这些函数将调用函数setParamater(int,Object,Type)。也就是说,与setParameter函数相同。
Should
setParameter
be used only with custom Objects?setParameter应该只用于自定义对象吗?
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.
不必要。我的意思是,你仍然可以使用Integer或其他包装类(Boolean,Float等)。就是这样,hibernate需要做一些额外的操作来检查值是什么类型并正确处理它。