What is the need for an unsaved-value attribute in hibernate?

前端 未结 2 1335
-上瘾入骨i
-上瘾入骨i 2020-12-08 22:05

What is the need for an unsaved-value attribute?

   
         


        
2条回答
  •  温柔的废话
    2020-12-08 22:34

    http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/mapping.html

    unsaved-value (optional - defaults to a "sensible" value): an identifier property value that indicates an instance is newly instantiated (unsaved), distinguishing it from detached instances that were saved or loaded in a previous session.

    In your example, unsaved-value="null" seems pretty pointless, since I suspect the "sensible default" for a Long is null.

    It's more useful for primitive types (e.g. int), which cannot be null, and the default unsaved-value of 0 may be undesirable in some applications (0 being a perfectly valid number value).

提交回复
热议问题