Hi All,
I ran into a problem in the versioning of the Canonical Data Model (CDM) with Hibernate where backwards compatibility for multiple versions is a must.
I am using JBoss 4.2.2
When we add functionality to a CDM descendent we invoke the default behavior of Hibernate and we need a discriminator type to be added to the table to keep track of which class created the row in the database. For example, the person entity is written using the Person class, so the default discriminator is "Person". Then you rev the Person Class to PersonV2, the default discriminator is "PersonV2"
When you try to retrieve the row, you can only cast it to that class type or any of its ancestors. This is expected behavior if you wanted to use polymorphism characteristics at the database level.
The problem comes when you try to pull back a list of persons using the PersonV2 type. You get class cast exceptions for all rows that have "Person" as the discriminator.
A way around this is to update the discriminator column to match the latest version's class name (e.g. "PersonV2"). But if a client has an older version of our CDM/web service jars, when they create a person, the discriminator is set to "Person". If I try and override the discriminator type (which I can see how to do) and set it to "PersonV2", when the client queries, they will get a ClassCastException.
If a client has the base version's jar ("Person") and tries to access a row that was saved with a later version ("PersonV2") then the client needs the PersonV2 class to complete the class definition and deserialize the class. So this doesn't work for clients with and older version of the CDM/web service jars, you get a ClassNotFoundException.
By the same token, if client using the latest version ("PersonV2") tries to look at a row that was created with a previous version (discriminator set to "Person"), you get a ClassCastException when Person is cast to PersonV2.
This functionality seems very broken to me for versioning. I can see the benefit for descendants that are different classes/logical types (for example, party, org and person) but I need to turn it off for my versioning scheme.
I am currently researching the solution, but I a day on this and am pretty frustrated. We could do it by hand and use native queries, decoupling it from the database, but this should be able to be completed.
If anyone has encountered this and knows how to address it, I would appreciate a reply....
Thanks - Mark
|