Home > Back-end >  Using spring data jpa new users to the database default values for the Java data type of the default
Using spring data jpa new users to the database default values for the Java data type of the default

Time:12-02

I want to be a user of new features, about twenty or thirty fields, and about 70% of the field is not empty restrictions, and set the default value (this limit is limited in a database table)
Now when I was in new users, through the save method adds a data repository, set the initial value to some fields, and entity class with the @ DynamicInsert annotations,
When I save to the database found that those who were not initialize the fields is not the default value of the database table, but the default value of Java data types, such as the level field, the database limit hi is: int the not null default level 1 and then through the debug found a value of 0

CodePudding user response:

@ DynamicInsert will keep not null field when generating SQL, pay attention to use the wrapper class basic types, for example, if you say that the level of the field, if a class is used in the int instead of an Integer, a default value of 0, not null
  • Related