for simplicity, here is my simplified model:
I got 2 entities:
@entity
public class Student {
int id;
School school
...
}
and the school is an entity as well
@entity
public class School {
int id;
...
}
im trying to pull a lot of data from a text file. some students have the same school instance, i wouldn't like multiple schools in my database with the same name, so my goal is to save each student in the student db , while making sure that 2 different students with the same school , wont create 2 entries in my school db.
problem is when i try to persist the students, it gives me an error: "detached entity passed to persist" , how do i tell hibernate, that the school in the student class is already exists in the database , and that it should use it instead?
thanks