Fei*_* Su 3 java spring entity boolean jpa
我有以下Comment实体:
@Entity
@Table(name = "comment")
public class Comment extends AbstractEntity
Run Code Online (Sandbox Code Playgroud)
其中一栏:
@Column(name = "is_deleted")
private Boolean isDeleted;
Run Code Online (Sandbox Code Playgroud)
返回的注释对象将变量名称从更改isDeleted为删除。
当我Comment从客户端调用中保存对象时。如果我说 isDeleted:false,我得到的是deleted:null。如果我说deleted:false,我得到的是deleted:false。所以看起来列名已被删除,但 isDeleted 并未被删除。
不知道为什么会出现这种情况。
整个评论实体代码:
package no.nsd.archivingportal.domain.comment;
import no.nsd.archivingportal.domain.AbstractEntity;
import no.nsd.archivingportal.domain.user.User;
import org.hibernate.annotations.Type;
import javax.persistence.*;
import java.util.UUID;
@Entity
@Table(name = "comment")
public class Comment extends AbstractEntity {
@Type(type="pg-uuid")
@Column(name = "commented_entity")
private UUID commentedEntity;
@ManyToOne
@JoinColumn(name = "user_id")
private User author;
@Column(name = "content")
private String content;
@Column(name = "is_deleted")
private Boolean isDeleted;
public UUID getCommentedEntity() {
return commentedEntity;
}
public void setCommentedEntity(UUID commentedEntity) {
this.commentedEntity = commentedEntity;
}
public User getAuthor() {
return author;
}
public void setAuthor(User author) {
this.author = author;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Boolean getDeleted() {
return isDeleted;
}
public void setDeleted(Boolean deleted) {
isDeleted = deleted;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
Comment comment = (Comment) o;
if (commentedEntity != null ? !commentedEntity.equals(comment.commentedEntity) : comment.commentedEntity != null)
return false;
if (author != null ? !author.equals(comment.author) : comment.author != null) return false;
if (content != null ? !content.equals(comment.content) : comment.content != null) return false;
return isDeleted != null ? isDeleted.equals(comment.isDeleted) : comment.isDeleted == null;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (commentedEntity != null ? commentedEntity.hashCode() : 0);
result = 31 * result + (content != null ? content.hashCode() : 0);
result = 31 * result + (isDeleted != null ? isDeleted.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Comment{" +
"commentedEntity=" + commentedEntity +
", author=" + author +
", content='" + content + '\'' +
", isDeleted=" + isDeleted +
'}';
}
}
Run Code Online (Sandbox Code Playgroud)
我认为问题在于你的isDeleted财产的获取者/设置者。
因此,要么将属性名称更改为deleted并保持 getter/setter 不变,要么更改 getter/setter 以更准确地反映属性的名称,例如
public Boolean getIsDeleted() {
return isDeleted;
}
public void setIsDeleted(Boolean deleted) {
isDeleted = deleted;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7572 次 |
| 最近记录: |