WrongClassException when doing session.merge()

Our lifecycle is, I believe, pretty common. We fetch objects from the database, serialize them to JSON and let client-side Javascript unpack it and fill in a form so our users can make changes. The data comes back and is loaded as Java objects by Struts. We re-fetch the original object from Hibernate and do a merge to update with new values.

We have a class, TargetProductGroup. It has a field of type BasicModel. BasicModel in turn has two subclasses, SlagModel and MgOSatModel. In this particular test case, the TargetProductGroup has a MgOSatModel. When we try to call merge, we get this exception:

WrongClassException: Object was not of the specified subclass [BasicModel]: class of the given object did not match class of persistent copy

We do check in the code that the local copy we get from session.find() has an MgOSatModel.

What Hibernate version do you use? Did you try updating to the latest version yet and see if that problem persists?

Sorry to have wasted your time. The actual problem was the reverse - our stupid web framework gave us a BasicModel, which of course can’t be merged with the MgOSatModel in the database …