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

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

What is the need for an unsaved-value attribute?

   
         


        
2条回答
  •  醉梦人生
    2020-12-08 22:28

    It is explained in this brilliant article:

    The Hibernate mapping file indicates that the id field on Person is the database ID (i.e. it is the primary key in the PERSON table). Within the id tag is an attribute, unsaved-value="null", that tells Hibernate to use the id field to determine whether a Person object has been previously saved or not. ORM frameworks must make this distinction to know whether they should save the object with a SQL INSERT or UPDATE statement. In this case, Hibernate assumes that the id field starts out null on new objects and is assigned when they are first saved.

    Also, you can read about "unsaved-value" in the book "Java Persistence with Hibernate":

    enter image description here

提交回复
热议问题