-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Hibernate3 table-per-subclass exception
PostPosted: Fri Dec 24, 2004 5:45 pm 
Regular
Regular

Joined: Fri Mar 26, 2004 11:45 am
Posts: 75
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)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 24, 2004 6:23 pm 
Regular
Regular

Joined: Fri Mar 26, 2004 11:45 am
Posts: 75
After a little more investigation I found out that Hibernate seems to map the table of the superclass to the first loaded subclass configuration. So, if Resource.hbm is loaded first, then Hibernate will always select fields of the Resource table when running queries against Entity table.

So, if Resource.hbm is loaded before Member.hbm and an entity with entity_type "resource" is found, then Hibernate maps it correctly to an object of the Resource class. However, if an Entity with entity_type "member" is found, then Hibernate joins all 3 tables, selects the fields of the Resource table and tries to map them to an object of the Member class. Hence, the JDBC result set exception.

Is this a Hibernate bug or smth silly on my part?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 27, 2004 5:28 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Can you provide more informations ie:
- a small working testcase
- the hbms
- etc

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 27, 2004 5:54 am 
Regular
Regular

Joined: Fri Mar 26, 2004 11:45 am
Posts: 75
I sent you an email at emmanuel@hibernate.org with a zipped Eclipse project.

Thanks.

Alec


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 27, 2004 6:42 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
I sent you an email at emmanuel@hibernate.org with a zipped Eclipse project.


it's not a good way....

please, use this forum and the code tag when showing sources.

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 27, 2004 9:40 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
alecswan wrote:
I sent you an email at emmanuel@hibernate.org with a zipped Eclipse project.

Come on, it's christmas, you gave me a 300k project ;-)
Honnestly I can't spend too much time, the problem has to be isolated (3 classes and a runnable test case) and posted to JIRA.
If you really can't, at least post it to JIRA with a simple description, one of ours will try to have a look.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 27, 2004 5:42 pm 
Regular
Regular

Joined: Fri Mar 26, 2004 11:45 am
Posts: 75
Sorry, I forgot about the Christmas thing. I'll resend it to you after the New Years then ;)

Seriously, I will try to isolate the problem to 3 classes and post to JIRA. I'll let you know when it's done.

Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.