简体   繁体   中英

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. should be 2 I want to know what's wrong with my annotations and thanks a lot

I guess you should specify @JoinColumn here as well:

@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>();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM