根据我的理解,nullable = false(例如对于列customerid)仅适用于使用Hibernate创建模式,并且在持久化之前不应进行任何类型的验证。我的数据库列没有此类约束(它可以接受null值),但在将具有customerid为null的实体持久化时,会出现此错误。
Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value :b
at org.hibernate.engine.internal.Nullability.checkNullability(Nullability.java:111) ~[hibernate-core-5.4.27.Final.jar:5.4.27.Final]
at org.hibernate.engine.internal.Nullability.checkNullability(Nullability.java:55) ~[hibernate-core-5.4.27.Final.jar:5.4.27.Final]
at
我将我的spring boot版本更新到2.4.2之后,这个错误开始不断出现。
实体类
public class FaceIndexResponse extends AuditEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(name="customer_id",nullable = false)
private String customerId;
@Column(name="application_id")
private String appid;}
我尝试保存上述实体的服务类
public IndexFacesResult handle(FaceIndexModel model) throws IOException{
FaceIndexResponse response=new FaceIndexResponse();
response.setAppid(model.getApplicationId);
faceIndexResponseJpa.save(response);
}
Table "public.face_index_response"
Column | Type | Collation | Nullable | Default
----------------+-----------------------------+-----------+----------+----------------------------------
id | integer | | not null | generated by default as identity
customer_id | character varying(64) | | |
application_id | character varying(64) | | |
null
,并且没有数据库约束,那么你为什么一开始使用nullable = false
呢? - crizzis