Dave Tolls wrote:The collection is persisted.
Via the other side of the relationship (ie the reference in Phone to the Employee it is associated with).
Mike Cheung wrote:Okay so you have similar annotations defined in the entity class. The following bit must be something you added in addition to the setters and getters generated automatically.
So you are handling the relationship from both ends also.
Your job.addRecord(rec); is similar to my emp.getPHONEID().add(ph);
Your rec.setJob(job); is similar to my ph.setEMPLOYEEID(emp);
In other words, I guess we have verified in both my and your case the following:
1) If persisting an object on the Many side (ie Phone for me and Record for you), we don't need to add any special functions. The generated setter is able to handle it.
Mike Cheung wrote:
2) If persisting an object on the One side (ie Employee for me and Job for you), we need to add a special function (ie addRecord in your case) on top of the generated getters and setters. This special function needs to manage relationships from both ends.
Mike Cheung wrote:
3) The Collection isn't persisted into the database. In your case, you will have a FK on the Records table pointing to a row on the Job table. But I don't believe you have any FKs on the Job table pointing to any rows on your Records table. This means the job.addRecord(rec); line can be commented out and you'll have the same result in the database.
Mike Cheung wrote:
Can you confirm by in fact commenting out the following line and see if you have the same result in your database as if it's not commented out?
job.addRecord(rec);
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |