Hello all.
When I try to execute the following query, Hibernate throws WrongClassException:
"from my.Item item where item.someProperty is not null"
The Item-related classes are arranged in such way:
my.Item
my.CatalogueItem extends my.Item
my.FullItem extends my.CatalogueItem
my.PriceItem extends my.Item
All these four classes point to one table and no discriminators are used. I realise it's wrong, but question is not about it...
When I execute the mentioned query, Hibernate would give error:
net.sf.hibernate.WrongClassException: Object with id: 2686978 was not of the specified subclass: my.CatalogueItem (loaded object was of wrong class)
at net.sf.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:300)
at net.sf.hibernate.loader.Loader.getRow(Loader.java:278)
at net.sf.hibernate.loader.Loader.doFind(Loader.java:159)
at net.sf.hibernate.loader.Loader.find(Loader.java:620)
at net.sf.hibernate.hql.QueryTranslator.find(QueryTranslator.java:928)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1343)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1322)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1314)
CatalogueItem, FullItem and PriceItem has polymorphism=implicit , but as I understand it has no effect without discriminators. So, what would this error mean?
I can simulate this exception in another way. Build the same scheme with classes and mappings, and:
open session;
ask to load my.Item;
ask to load my.CatalogueItem;
It would load my.Item's all right, but would give the exception on loading CatalogueItem's. As I understand, it's because object from this table with this ID was already loaded before, and is still in the session's cache. However, using evict() doesn't help...
Fine, but this case is different from the previous, where I ask to load only my.Item ... The cache should be empty. That's puzzling...
Why could it happen..?
--Thanks in advance,
yura
P.S. hibernate 2.0.3
|