I'm working on a spring boot application and i'm using JPA and hibernate.
I'm facing a problem with the mapping relation between two entities User and Evaluation.
the main idea is to evaluate a user via another one (evaluaters)
User.java
public class User implements Serializable {
private static final long serialVersionUID = 1209816669845063949L;
@Id
@GeneratedValue
private int idUser;
private String login;
private String password;
@ManyToMany(mappedBy = "listUsers")
private List<ProjectGroup> listProjectGroup;
@OneToOne(mappedBy = "EvaluatedUser")
private Evaluation evaluation1;
@OneToOne(mappedBy = "Evaluater")
private Evaluation evaluation;
}
Evaluation.java
public class Evaluation {
@Id
@GeneratedValue
private int idEvaluation;
@OneToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinColumn(name = "evaluateduser_fk")
private User EvaluatedUser;
@OneToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinColumn(name = "evaluater_fk")
private User Evaluater;
@OneToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinColumn(name = "project_fk")
private Project project;
@OneToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinColumn(name = "notes_fk")
private Notes notes;
}
EvaluationController.java
I'm using this method to return all the evaluations
@GetMapping(path = "all-evaluation", produces = {"application/json" })
public ResponseEntity<List<Evaluation>> getAllEvaluations() {
List<Evaluation> list = evaluationService.findAll();
return new ResponseEntity<List<Evaluation>>(list, HttpStatus.OK);
}
The problem is, i can't evaluate the same user twice, i think the problem is with my relation OneToOne
This is the exception i'm getting while returning the json :
There was an unexpected error (type=Internal Server Error, status=500). More than one row with the given identifier was found: 1, for class: com.talan.entity.Evaluation; nested exception is org.hibernate.HibernateException: More than one row with the given identifier was found: 1, for class: com.talan.entity.Evaluation
Any help would be apreciated