创建一个自定义的Hibernate UserType - isMutable()是什么意思? [英] Creating a custom Hibernate UserType - What does isMutable() mean?
问题描述
我在Hibernate中为一个项目创建一个自定义的UserType。直到我接触到isMutable方法时,它一直比较简单。我试图找出这种方法意味着什么,合同明智。
它是否意味着我创建UserType的类是不可变的,还是它意味着持有对此类实例的引用永远不会指向不同的对象实例?
我在 Hibernate社区发现了一些例子Wiki ,他们在那里返回true,因为对象本身是可变的 - http://www.hibernate。组织/ 73.html 。
社区wiki中的其他示例在没有解决原因的情况下返回false,即使它们也是可变的。
I已经检查了JavaDoc,但它也不是很清楚。
从JavaDoc for 从JavaDoc for 类型:
public boolean isMutable()
这种类型的对象是否可变?
返回:
boolean
public boolean isMutable()
这种类型的对象是可变的。 (关于引用
对象...实体和集合被认为是不可变的,因为
他们管理自己的内部状态。)
返回:
布尔
Hibernate会将标记为可变的类型视为可以改变(即需要一个UPDATE)没有指向一个新的引用。如果你为一个Hibernate加载的属性赋值一个新的引用,即使类型是不可变的,Hibernate也会识别这个 - 这种情况会一直发生,比如String字段。
但是,如果你有一个StringBuilder字段,并且将它标记为不可变,那么如果修改StringBuilder,Hibernate将不是注意。
请参阅此博客文章以获取更多详情和示例项目。
I am creating a custom UserType in Hibernate for a project. It has been relatively straightforward until I came to the isMutable method. I am trying to figure out what this method means, contract-wise.
Does it mean the class I am creating the UserType for is immutable or does it mean the object that holds a reference to an instance of this class will never point to a different instance?
I found some examples in the Hibernate Community Wiki where they returned true, because the object itself was mutable - http://www.hibernate.org/73.html.
Other examples in the community wiki returned false without addressing why, even though they were also mutable.
I have checked the JavaDoc, but it's not very clear either.
From the JavaDoc for UserType:
public boolean isMutable()
Are objects of this type mutable?
Returns:
boolean
From JavaDoc for Type:
public boolean isMutable()
Are objects of this type mutable. (With respect to the referencing
object ... entities and collections are considered immutable because
they manage their own internal state.)
Returns:
boolean
Hibernate will treat types marked as "mutable" as though they could change (i.e. require an UPDATE) without pointing to a new reference. If you assign a new reference to a Hibernate-loaded property Hibernate will recognize this even if the type is immutable - this happens all the time with, for instance, String fields. But if, say, you have a StringBuilder field and you mark it as immutable Hibernate will not notice if you modify the StringBuilder.
See this blog post for more details and a sample project.
这篇关于创建一个自定义的Hibernate UserType - isMutable()是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!