emmettwalsh wrote:
I have a relationship between two tables which Im not sure sure is actually
possible to model with hibernate or not.
Sounds to me like you have two classes that should extend User (using a
single table for the entire class hierarchy). You can have a
one-to-many relationship between each class and the ScheduleEntry class
(each Schedule Entry is limited to at most one producer and one
scheduler according to your description), and implement
getScheduleEntries() differently in each of them to return different
types of relationships.
The corner case that will cause you trouble is if you ever decide that a
producer should be able to schedule an appointment with another
producer, as that is excluded from your description.
I also have the following additional requirements:
If I am a 'producer' user and I get deleted, my associated scheduleentries
should get deleted aswell
If I am a 'consumer' user and I get deleted, my associated scheduleentries
should get deleted aswell
These are just the cascade settings.
In the object model, if a scheduleentry gets deleted I want its reference in
the lists held by the producer user and the customer user to get deleted
also, so that they are not hanging on to stale lists.
That you have to do yourself, but should be as simple as putting the
following in your delete method:
if (se != null) {
if (se.getProvider() != null) {
Provider p = se.getProvider();
List<ScheduleEntry> appointmentBook = p.getScheduleEntries();
if (appointmentBook != null) {
appointmentBook.remove(se);
p.setScheduleEntries(appointmentBook);
}
}
if (se.getConsumer() != null) {
Consumer c = se.getProvider();
List<ScheduleEntry> appointments = c.getScheduleEntries();
if (appointments != null) {
appointments.remove(se);
c.setScheduleEntries(appointments);
}
}
}
-Dale
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]