When we started using Hibernate 2.x, my team and I encountered a problem dealing with our table-per-hierarchy mapping. Basically, we are looking for a way in Hibernate 3.x to force the discriminator column to be checked/changed at each update.
Here is a hypothetical situation:
School Object contains an Array of People Objects. Student and Teacher Objects extend People Object. People, Student, and Teacher share a single database table that uses a String discriminator value.
There exists the opportunity that a Student will become a Teacher. We cannot (for the scope of my project) delete the Student and insert it as a new Teacher. Therefore, we want to take the People fields from Student, put them in a Teacher object. We want to then take the key from the Student object and assign it to the new Teacher object.
Now, when we do a update (or saveOrUpdate) on the Teacher Object, all of the Teacher fields get persisted to the database but the discriminator value never changes. So when you go to retrieve the object from the database you get a odd mish-mash of values.
Now, in Hibernate 2.x we over came this problem by taking the hibernate source code and modifying the generateUpdate() method of one its single-table-class persister (I forget the name off the top of my head). Basically we forced it to include the discriminator in the updates.
Now that we have upgraded to Hibernate 3.x we have to go back into the source code and muck-around to get it to do what we want it to do.
I was hoping that maybe someone knows a better work around or solution to this problem.
Thanks
_________________ Brian
|