Hi
We have a workaround for this but if anyone knows the reason why I'd be pleased to here.
We have an application that stores a User object in the http session.
As this object has lazy associations we rebind it to the current hibernate session each request (using lock and if that fails merge).
User has a link to the owning Company. Company is an abstract class , which is the parent of Brand, Dealer etc. Typed companies have links to other typed companies. For example Dealer getParent() returns a sales company and sales company getParent() returns a Group Company and so on.
These are all mapped correctly and typed. Company has no getParent() method, it is only implemented in the concrete sub classes.
When we use the Company returned by user.getCompany() this can cause a problem wih the 'narrowing' issue because the company proxy is not a dealer proxy etc. We understand this and have taken steps to avoid the problem.
However, this is the strange part. If we wait on a screen for five minutes the application occasionally blows up when we bind the user to the Hibernate session on the next request, because we cascade the lock down from company to the linked companies and we get a class cast exception saying expected Group Company got Admin Organisation. There is nothing wrong with the data and if we hadn't waited for a few minutes the code would have worked.
Our feeling is that either the http session is being written to disk and corrupting the object in session or the Hibernate second level cache is being written to disk and the object returned is corrupted.
As I say , we have a workaround (don't use hibernate objects in Http Session!) but I'd be happy to hear if anyone can explain this conundrum.
Thanks
Nick
|