I'm mapping two objects: Professor and Vehicles, it's a n to n relationship so I'm using a relationship table called "rel_prof_vehicle". The problem comes when it comes to obtaining any object Professor or Vehicles, it brings me the whole object but in the set of vehicles or professors that have respectively I get the following error:
com.sun.jdi.InvocationException occurred invoking method
I've looked through stackoverflow and people say it's by the toString method, but it's self-generated:
@Override
public String toString() {
return "Professor [professorId=" + professorId + ", firstName=" + firstName + ", lastName=" + lastName
+ ", dni=" + dni + ", email=" + email + ", birthdate=" + birthdate + ", phone=" + phone + ", home="
+ home + ", vehicles=" + vehicles + "]";
}
I also leave the mappings too. Professor:
@ManyToMany(fetch = FetchType.LAZY,
cascade = {
CascadeType.PERSIST,
CascadeType.MERGE
})
@JoinTable(name = "rel_prof_vehicle",
joinColumns = { @JoinColumn(name = "professor_id") },
inverseJoinColumns = { @JoinColumn(name = "vehicle_id") })
public Set<Vehicle> getVehicles() {
return vehicles;
}
Vehicle:
@ManyToMany(fetch = FetchType.LAZY,
cascade = {
CascadeType.PERSIST,
CascadeType.MERGE
},
mappedBy = "vehicles")
public Set<Professor> getProfessors() {
return professors;
}
I have been browsing and viewing mappings of objects n to n in jpa, but I have not gotten them working, if they knew of some place or another way of mapping them (same with ManyToOne) I would appreciate it. Before you ask, in the database I have the foreign keys of the table related to professor and vehicle.