I am doing a simple Poll system. I have 2 tables:
Person
: ID, Name, Surname
Vote
: ID, Vote (Boolean), VoterID (This is actually FK_PersonID
), PersonID (This is actually FK_PersonID
as well).
I need to be able to identify who cast the vote as well as who the vote was for - using the people stored in the Person
table for both of these needs. The table Person
contains user details of people that can "Vote" as well as be "Voted for". People are allowed to decide whether they want to vote for themselves or not.
I've mapped out my tables in my domain
objects like this:
Person
private Integer ID;
private String name;
private String surname;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
public Integer getID() {
return ID;
}
public void setID(Integer ID) {
this.ID = ID;
}
@Column(name = "name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "surname")
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
Vote
private Integer ID;
private Person voter;
private Person person;
private Boolean vote;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
public Integer getID() {
return ID;
}
public void setID(Integer ID) {
this.ID = ID;
}
@Column(name = "vote")
public Boolean getVote() {
return vote;
}
public void setVote(Boolean vote) {
this.vote = vote;
}
@ManyToOne
@JoinColumn(name = "personID")
public Person getVoter() {
return voter;
}
public void setVoter(Person voter) {
this.voter = voter;
}
@ManyToOne
@JoinColumn(name = "personID")
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
Error message
Caused by: org.hibernate.MappingException: Repeated column in mapping
for entity: web.poll.domain.Vote column: personID (should be mapped
with insert="false" update="false")
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…