2016-10-04 7 views
2

I以下Commentエンティティがあります。春のJPAエンティティブール変数名を変更したときのリターンエンティティオブジェクト

@Entity 
@Table(name = "comment") 
public class Comment extends AbstractEntity 

と列の1:

@Column(name = "is_deleted") 
    private Boolean isDeleted; 

返されたコメントオブジェクトはから変数名を変更しますisDeletedを削除してください。

クライアントコールからCommentオブジェクトを保存したとき。私が言うならisDeleted:false、そして私が得るものは削除されます:null。私が削除と言う場合:false、私が得るものは削除されます: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 + 
       '}'; 
    } 
} 
+0

「返されたコメントオブジェクトは、isDeleted変数名を削除する」とはどういう意味ですか? – pleft

+0

戻り値:isDeleted:true/false。 しかし、私が得るものは削除されます:null/true/false。 –

+0

'isDeleted'プロパティのgetter/setterメソッドがありますか?あなたもそれらを投稿できますか?実際に 'Comment'クラス全体を投稿します。私の意見では、クラス内で 'isDeleted'プロパティの名前を' deleted'に変更する必要があります。 – pleft

答えて

3

私はこの問題はisDeleted財産のあなたのゲッター/セッターであると思います。

プロパティ名をdeletedに変更し、ゲッター/セッターをそのまま使用するか、ゲッター/セッターを変更して、プロパティ名 をより正確に反映させます。

+0

ありがとうございます。なぜこれが起こるのでしょうか? "isDeleted"は予約されていますか? –

関連する問題