我试图保存诊所实体与OneToOne nullable = false
关系与用户实体。
临床实体:
//....Some fields
@OneToOne(optional=false,fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
@NotNull
private User user;
//.. Getters & Setters
用户实体
//....Some fields
@OneToOne(fetch = FetchType.LAZY,mappedBy="user",cascade=CascadeType.ALL,orphanRemoval = true)
private Clinic clinic;
//.. Getters & Setters
违反约束的列表: ConstraintViolationImpl{interpolatedMessage='may not null',propertyPath=user,rootBeanClass=class com.domain.entity.Clinic,messageTemplate='{javax.validation.constraints.NotNull.message}'}
发布于 2017-04-20 08:25:11
多亏了@Alan ,我错过了在诊所实体中添加setUser() & getUser()
的错误。
在加入它们之后,就像一种魅力,..
curl -i -X POST -H "Content-Type: application/json" -d '{"name":"clinc","address":"address","city":"city","area":"area","user":"http://localhost:8080/clinicfinder/api/user/2"}' http://localhost:8080/clinicfinder/api/clinic
HTTP/1.1 201 Created
Server: Apache-Coyote/1.1
Location: http://localhost:8080/clinicfinder/api/clinic/1
Content-Type: application/hal+json;charset=UTF-8
Transfer-Encoding: chunked
Date: Thu, 20 Apr 2017 15:59:16 GMT
{
"name" : "clinc",
"address" : "address",
"city" : "city",
"area" : "area",
"longitude" : null,
"latitude" : null,
"createDate" : null,
"updateDate" : null,
"doctors" : [ ],
"_links" : {
"self" : {
"href" : "http://localhost:8080/clinicfinder/api/clinic/1"
},
"clinic" : {
"href" : "http://localhost:8080/clinicfinder/api/clinic/1"
},
"user" : {
"href" : "http://localhost:8080/clinicfinder/api/clinic/1/user"
}
}
}
https://stackoverflow.com/questions/43520267
复制相似问题