简体   繁体   English

外键引用的列数错误。 应该是 2

[英]A Foreign key refering has the wrong number of column. should be 2

Here is my code这是我的代码

VirsualPerson虚拟人

public class VirsualPerson extends Person{

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@PrimaryKeyJoinColumn(name="VIRSUALPERSON_ID")
private long virsualPersonId;

@ManyToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL)
@JoinTable(name="Anime_character",catalog="anime",joinColumns={
        @JoinColumn(name="VIRSUALPERSON_ID",nullable=false)},inverseJoinColumns={@JoinColumn(name="ANIME_ID",nullable=false)})
private Set<Anime>animeCharacters=new HashSet<Anime>();


@OneToMany(fetch=FetchType.LAZY,mappedBy="charecter")
private Set<VirsualPeopleComment>comments=new HashSet<VirsualPeopleComment>();

public long getVirsualPersonId() {
    return virsualPersonId;
}
public void setVirsualPersonId(long virsualPersonId) {
    this.virsualPersonId = virsualPersonId;
}
public Set<Anime> getAnimeCharacters() {
    return animeCharacters;
}
public void setAnimeCharacters(Set<Anime> animeCharacters) {
    this.animeCharacters = animeCharacters;
}
public Set<VirsualPeopleComment> getComments() {
    return comments;
}
public void setComments(Set<VirsualPeopleComment> comments) {
    this.comments = comments;
}

} }

VirsualPersonComment虚拟人评论

@Entity
@Table(name="people_comment")
public class VirsualPeopleComment {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="peopleCommentId")
private long commentId;

@Column(name="content")
private String commentContent;

@Temporal(TemporalType.TIMESTAMP)
@Column(name="POST_TIME")
private Date postTime;


@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="USER_ID")
private User commentUser;

@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="VIRSUALPERSON_ID")
private VirsualPerson charecter;

public long getCommentId() {
    return commentId;
}
public void setCommentId(long commentId) {
    this.commentId = commentId;
}
public String getCommentContent() {
    return commentContent;
}
public void setCommentContent(String commentContent) {
    this.commentContent = commentContent;
}

public Date getPostTime() {
    return postTime;
}
public void setPostTime(Date postTime) {
    this.postTime = postTime;
}

public User getCommentUser() {
    return commentUser;
}
public void setCommentUser(User commentUser) {
    this.commentUser = commentUser;
}
public VirsualPerson getCharecter() {
    return charecter;
}
public void setCharecter(VirsualPerson charecter) {
    this.charecter = charecter;
}

} }

And here is the error这是错误

A Foreign key refering VirsualPerson from VirsualPeopleComment has the wrong number of column.从 VirsualPeopleComment 引用 VirsualPerson 的外键具有错误的列数。 should be 2 I want to know what's wrong with my annotations and thanks a lot应该是 2我想知道我的注释有什么问题,非常感谢

I guess you should specify @JoinColumn here as well:我想你也应该在这里指定@JoinColumn:

@OneToMany(fetch=FetchType.LAZY,mappedBy="charecter")
private Set<VirsualPeopleComment>comments=new HashSet<VirsualPeopleComment>();

looks like it should be看起来应该是

@OneToMany(fetch=FetchType.LAZY,mappedBy="charecter")
@JoinColumn(name="peopleCommentId")
private Set<VirsualPeopleComment>comments=new HashSet<VirsualPeopleComment>();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AnnotationException: 引用的外键列数错误。 应该是 0 - AnnotationException: A Foreign key refering has the wrong number of column. should be 0 AnnotationException:引用dayHibernate的外键…错误的列数。 应该是3 - AnnotationException: A Foreign key refering dayHibernate … wrong number of column. should be 3 Hibernate Mapping中的错误“外键引用的列数错误。 应该是2“ - Error in Hibernate Mapping “A Foreign key refering has the wrong number of column. should be 2” org.hibernate.AnnotationException:外键引用的列数错误。 应该是2 - org.hibernate.AnnotationException: A Foreign key refering has the wrong number of column. should be 2 hibernate4:引用的外键列数错误。 应该是 2 - hibernate4: A Foreign key refering has the wrong number of column. should be 2 org.hibernate.AnnotationException:从Y引用X的外键具有错误的列数。 应该是2 - org.hibernate.AnnotationException: A Foreign key refering X from Y has the wrong number of column. should be 2 org.hibernate.AnnotationException:从y引用x的外键具有错误的列数。 应该是n - org.hibernate.AnnotationException:A Foreign key refering x from y has the wrong number of column. should be n Hibernate:外键的列数错误。 应该是 1 - Hibernate: a foreign key has the wrong number of column. should be 1 从MainTableEntity引用MasterDataEntity的外键具有错误的列数 - A Foreign key refering MasterDataEntity from MainTableEntity has the wrong number of column JPA-错误的列数。 应该是2 - JPA - wrong number of column. should be 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM