Creating a custom Hibernate UserType - What does isMutable() mean?

后端 未结 2 557
-上瘾入骨i
-上瘾入骨i 2021-01-12 00:15

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

相关标签:
2条回答
  • 2021-01-12 01:13

    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.

    0 讨论(0)
  • 2021-01-12 01:13

    The typical example here is the String class - it is Immutable, i.e. once the string is created you cannot change its contents or state, and if you want to then you're going to have to process it into a new copy.

    isMutable returning true means you are saying this object can have its state changed by outside objects, returning false means you will have to copy this object to a new instance makign the changes to state along the way. Or as you said: "does it mean the object that holds a reference to an instance of this class will never point to a different instance".

    0 讨论(0)
提交回复
热议问题