Well, thanks to y'all I figured it out, but I have to admit, it's a little hokey...
Like I mentioned on my above post, putting a reference to the doctor into the appointment makes me unconfortable. Doesn't that require you break abstraction? So, to make myself feel better, I created a class DoctorsAppointment that extends Appointment, and put my reference to Doctor in there.
public class DoctorsAppointment extends Appointment {
private Doctor doctor;
public Doctor getDoctor() {
return doctor;
}
public void setDoctor(Doctor doctor) {
this.doctor = doctor;
}
}
Then, I modified my Doctor.hbm.xml to include a set of DoctorsAppointments:
<set name="appointments" inverse="true" cascade="save-update">
<key column="doctor_id" not-null="true" />
<one-to-many class="com.servicesoftheweb.scheduler.DoctorsAppointment" />
</set>
Then, the many-to-one relationship in DoctorsAppointment.hmb.xml:
<many-to-one name="doctor" class="com.servicesoftheweb.scheduler.Doctor" column="doctor_id"/>
Now, the part that's really weird, and maybe I'm doing this wrong, is when I tried to persist the set to the database, the foreign-key (Doctor ID), was always coming in null! Why!?
After some research, I found out that once I created the appointments for the doctor, I also needed to set the doctor for the appointments! You would *think* that since your adding a child to the parent, you wouldn't think you'd also have to add the parent to the child!
Doctor surgon = new Doctor();
surgon.setName("Dr. Christopher Duncan Turk");
DoctorsAppointment removeBrain = new DoctorsAppointment();
removeBrain.setAppointmentTime(2007, 3, 7, 15, 15);
removeBrain.setAppointmentLength(300);
removeBrain.setDescription("Remove Brain from Ms. Abby Normal.");
DoctorsAppointment tripleBypass = new DoctorsAppointment();
tripleBypass.setAppointmentTime(2007, 02, 31, 13, 00);
tripleBypass.setAppointmentLength(450);
tripleBypass.setDescription("Do Triple Bypass on Mr. Rogers.");
surgon.setAppointments(new HashSet());
surgon.getAppointments().add(removeBrain);
removeBrain.setDoctor(surgon);
surgon.getAppointments().add(tripleBypass);
tripleBypass.setDoctor(surgon)
session.saveOrUpdate(surgon);
... Is this the correct way, or am I doing this bassackwards?
Thanks!
-- Casey
[ March 14, 2007: Message edited by: Casey Kcins ]
[ March 14, 2007: Message edited by: Casey Kcins ]