I started using Hibernate3 and am getting the following exception:
org.hibernate.exception.GenericJDBCException: could not load an entity: [data.Entity#88]
Here is what I am trying to do. I have a Resource and Member classes, which extend the Entity class. Entity class contains entity_type column (which contains either "resource" and "member" strings), which I use as a discriminator in the <join> element similar to Gavin's example in
http://blog.hibernate.org/cgi-bin/blosx ... 08/25#join.
The configuration files are loaded in the following order:
Entity.hbm, Resource.hbm, Member.hbm
In my test class I create and persist a Resource object and then I create and persist a Member object. After that I am trying to load the stored Resource object using EntityDAO.load(Long id) method. It works just fine and Hibernate checks the entity_type discriminator field, joins Entity and Resource table, loads the values and returns the right Resource object.
After this I am trying to load the stored Member object. However, for some reason Hibernate joins ALL three tables and then throws that exception above when trying to load the Member object. It seems that Hibernate does not check the discriminator field correctly in this case and joins all 3 tables.
Interestingly, if I switch the order of loading configuration files to:
Entity.hbm, Member.hbm, Resource.hbm and try to load stored Member object first it works fine, i.e. Hibernate joins just TWO tables Entity and Member and loads the Member object correctly. However, if after that I try to load the stored Resource object I get the error above.
It seems that my configuration is correct and Hibernate fails to load objects of the second subclass.
Any ideas?
P.S. Below is the complete stack trace:
org.hibernate.exception.GenericJDBCException: could not load an entity: [data.Entity#88]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1142)
at org.hibernate.loader.EntityLoader.load(EntityLoader.java:111)
at org.hibernate.loader.EntityLoader.load(EntityLoader.java:97)
at org.hibernate.persister.BasicEntityPersister.load(BasicEntityPersister.java:2302)
at org.hibernate.event.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:352)
at org.hibernate.event.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:333)
at org.hibernate.event.DefaultLoadEventListener.load(DefaultLoadEventListener.java:158)
at org.hibernate.event.DefaultLoadEventListener.load(DefaultLoadEventListener.java:131)
at org.hibernate.event.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:193)
at org.hibernate.event.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:115)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:694)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:689)
at com.sww.calendar.data.base._BaseRootDAO.load(_BaseRootDAO.java:591)
at com.sww.calendar.data.base._BaseRootDAO.load(_BaseRootDAO.java:580)
at com.sww.calendar.data.base.BaseEntityDAO.load(BaseEntityDAO.java:36)
at com.sww.calendar.engine.CalendarTest.main(CalendarTest.java:63)
Caused by: org.postgresql.util.PSQLException: Result set not positioned properly, perhaps you need to call next().
at org.postgresql.jdbc1.AbstractJdbc1ResultSet.checkResultSet(AbstractJdbc1ResultSet.java:823)
at org.postgresql.jdbc1.AbstractJdbc1ResultSet.getString(AbstractJdbc1ResultSet.java:200)
at org.postgresql.jdbc1.AbstractJdbc1ResultSet.getFixedString(AbstractJdbc1ResultSet.java:792)
at org.postgresql.jdbc1.AbstractJdbc1ResultSet.getLong(AbstractJdbc1ResultSet.java:292)
at org.postgresql.jdbc1.AbstractJdbc1ResultSet.getLong(AbstractJdbc1ResultSet.java:506)
at org.hibernate.type.LongType.get(LongType.java:26)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:62)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:53)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:70)
at org.hibernate.persister.BasicEntityPersister.hydrate(BasicEntityPersister.java:1521)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:802)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:760)
at org.hibernate.loader.Loader.getRow(Loader.java:671)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:278)
at org.hibernate.loader.Loader.doQuery(Loader.java:366)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:193)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1133)