Primary key database type integer increment primary key set, but still being given Could not set property 'id' xxx of 'class argument type mismatch

This is because, id can not insert because although the database has been set up primary key and increment, but the use of annotations entity, need another additional configuration for the job:

Solution: Add the following annotation above the primary key.

 

@TableId(value = "id",type= IdType.AUTO)

If the type of the primary key of type int into the integer can be achieved, but see colleagues integer type code is also used.

Baidu has about why to use integer 

2, the benefits of using wrapper classes

a), when we do not want to set any value of this property, we can give it a null value (provided that the field of the database allows the insertion of NULL).

b), we can verify pojo annotation class attribute's value validator (e.g.: javax.validation.constraints.NotNull)

 

4. Compare the two in the actual development of

a), if your database fields are allowed to be empty, use a wrapper class. If not empty, when the use of packaging, if you insert null values ​​into the database, then it will throw an exception. Then you will be able to capture and process anomalies.

b), when using the basic data types, if the field is NULL, then the JDBC returns 0, but there will be a problem. There may be 0 represents a specific meaning in your business logic, this time on a number of unintended consequences that may arise

Guess you like

Origin www.cnblogs.com/ctrlMusic/p/12334656.html