You'll find all the debug info below. I've seen a few moderately similar problems posted in the forum, but nothing seems to fix me.
Here's what I've got. A class hierarchy starting with:
Authorization
- UserAuthorization
-- UserActivationAdjustmentAuthorization
-- UserTimebankAdjustmentAuthorization
I would expect to be able to say (and this is what I'm trying):
session.find("from UserAuthorization auth where auth.guid = ?")
[ returning both Activation and Timebank authorizations if the auth.guid condition were not there. ]
Or even
session.load(UserAuthorization.class, authGuid);
Either way I end up with a WrongClassException that states my object is not of the specified subclass. It's saying "Authorization" is the subclass when it's really "UserActivationAdjustmentAuthorization" that is the subclass
Hibernate version: 2.1.7
Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.aebn.aia.core.domain.authorization.Authorization" table="AiaAuthorization">
<id name="guid" column="guid" type="java.lang.String">
<generator class="uuid.hex"/>
</id>
<discriminator column="type" force="true" insert="true"/>
<many-to-one name="partner" class="com.aebn.aia.core.domain.Partner" column="partner_guid"/>
<property name="created" type="long" column="created" update="false" insert="false"/>
<subclass name="com.aebn.aia.core.domain.authorization.UserAuthorization">
<many-to-one name="user" class="com.aebn.aia.core.domain.User" column="user_guid"/>
<subclass name="com.aebn.aia.core.domain.authorization.UserActivationAdjustmentAuthorization">
<property name="userActiveState" type="boolean" column="user_active_state"/>
</subclass>
<subclass name="com.aebn.aia.core.domain.authorization.UserTimebankAdjustmentAuthorization">
<property name="userTimebankAdjustment" type="integer" column="user_timebank_adjustment"/>
<property name="userTimebankMediaFormat" type="integer" column="user_timebank_media_format"/>
<property name="userTimebankBalance" type="integer" column="user_timebank_balance"/>
</subclass>
</subclass>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
UserAuthorization auth;
try {
auth = (UserAuthorization)getHibernateTemplate().find(
"from UserAuthorization auth where auth.guid = ?",
authorizationGuid).get(0);
} catch (ArrayIndexOutOfBoundsException e) {
throw new UnknownAuthorizationException();
}
return (auth);
Full stack trace of any exception that occurs:
[junit] net.sf.hibernate.WrongClassException: Object with id: 4028815a00f816aa0100f816b1240007 was not of the specified s
ubclass: com.aebn.aia.core.domain.authorization.UserAuthorization (Discriminator: com.aebn.aia.core.domain.authorization.User
TimebankAdjustmentAuthorization )
[junit] at net.sf.hibernate.loader.Loader.getInstanceClass(Loader.java:656)
[junit] at net.sf.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:569)
[junit] at net.sf.hibernate.loader.Loader.getRow(Loader.java:501)
[junit] at net.sf.hibernate.loader.Loader.getRowFromResultSet(Loader.java:213)
[junit] at net.sf.hibernate.loader.Loader.doQuery(Loader.java:281)
[junit] at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
[junit] at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
[junit] at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
[junit] at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
[junit] at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1553)
[junit] at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
[junit] at org.springframework.orm.hibernate.HibernateTemplate$24.doInHibernate(HibernateTemplate.java:506)
[junit] at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:228)
[junit] at org.springframework.orm.hibernate.HibernateTemplate.executeFind(HibernateTemplate.java:248)
[junit] at org.springframework.orm.hibernate.HibernateTemplate.find(HibernateTemplate.java:497)
[junit] at org.springframework.orm.hibernate.HibernateTemplate.find(HibernateTemplate.java:492)
[junit] at com.aebn.aia.core.dao.hibernate.UserAuthorizationDaoImpl.getUserAuthorization(UserAuthorizationDaoImpl.jav
a:60)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[junit] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:295)
[junit] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.ja
va:154)
[junit] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:121)
[junit] at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:56)
[junit] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:143)
[junit] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
[junit] at $Proxy2.getUserAuthorization(Unknown Source)
[junit] at com.aebn.aia.core.dao.AbstractUserAuthorizationDaoTest.testUserTeimbankAdjustAuthorizationSaved(AbstractUs
erAuthorizationDaoTest.java:80)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
Name and version of the database you are using:
Microsoft SQL Server 2000
The generated SQL (show_sql=true):
[junit] Hibernate: select userauthor0_.guid as guid, userauthor0_.type as type, userauthor0_.user_guid as user_guid, user
author0_.partner_guid as partner_3_, userauthor0_.created as created, userauthor0_.user_active_state as user_act6_, userautho
r0_.user_timebank_adjustment as user_tim7_, userauthor0_.user_timebank_media_format as user_tim8_, userauthor0_.user_timebank
_balance as user_tim9_ from AiaAuthorization userauthor0_ where userauthor0_.type in ('com.aebn.aia.core.domain.authorization
.UserTimebankAdjustmentAuthorization', 'com.aebn.aia.core.domain.authorization.UserAuthorization', 'com.aebn.aia.core.domain.
authorization.UserActivationAdjustmentAuthorization') and ((userauthor0_.guid=? ))
Debug level Hibernate log excerpt:
[junit] 19:06:23,094 DEBUG [hql.QueryTranslator] compiling query
[junit] 19:06:23,094 DEBUG [hql.QueryTranslator] HQL: from com.aebn.aia.core.domain.authorization.UserAuthorization auth
where auth.guid = ?
[junit] 19:06:23,094 DEBUG [hql.QueryTranslator] SQL: select userauthor0_.guid as guid, userauthor0_.type as type, userau
thor0_.user_guid as user_guid, userauthor0_.partner_guid as partner_3_, userauthor0_.created as created, userauthor0_.user_ac
tive_state as user_act6_, userauthor0_.user_timebank_adjustment as user_tim7_, userauthor0_.user_timebank_media_format as use
r_tim8_, userauthor0_.user_timebank_balance as user_tim9_ from AiaAuthorization userauthor0_ where userauthor0_.type in ('com
.aebn.aia.core.domain.authorization.UserTimebankAdjustmentAuthorization', 'com.aebn.aia.core.domain.authorization.UserAuthori
zation', 'com.aebn.aia.core.domain.authorization.UserActivationAdjustmentAuthorization') and ((userauthor0_.guid=? ))
[junit] 19:06:23,094 DEBUG [impl.BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
[junit] 19:06:23,094 DEBUG [hibernate.SQL] select userauthor0_.guid as guid, userauthor0_.type as type, userauthor0_.user
_guid as user_guid, userauthor0_.partner_guid as partner_3_, userauthor0_.created as created, userauthor0_.user_active_state
as user_act6_, userauthor0_.user_timebank_adjustment as user_tim7_, userauthor0_.user_timebank_media_format as user_tim8_, us
erauthor0_.user_timebank_balance as user_tim9_ from AiaAuthorization userauthor0_ where userauthor0_.type in ('com.aebn.aia.c
ore.domain.authorization.UserTimebankAdjustmentAuthorization', 'com.aebn.aia.core.domain.authorization.UserAuthorization', 'c
om.aebn.aia.core.domain.authorization.UserActivationAdjustmentAuthorization') and ((userauthor0_.guid=? ))
[junit] Hibernate: select userauthor0_.guid as guid, userauthor0_.type as type, userauthor0_.user_guid as user_guid, user
author0_.partner_guid as partner_3_, userauthor0_.created as created, userauthor0_.user_active_state as user_act6_, userautho
r0_.user_timebank_adjustment as user_tim7_, userauthor0_.user_timebank_media_format as user_tim8_, userauthor0_.user_timebank
_balance as user_tim9_ from AiaAuthorization userauthor0_ where userauthor0_.type in ('com.aebn.aia.core.domain.authorization
.UserTimebankAdjustmentAuthorization', 'com.aebn.aia.core.domain.authorization.UserAuthorization', 'com.aebn.aia.core.domain.
authorization.UserActivationAdjustmentAuthorization') and ((userauthor0_.guid=? ))
[junit] 19:06:23,094 DEBUG [impl.BatcherImpl] preparing statement
[junit] 19:06:23,094 DEBUG [type.StringType] binding '4028815a00f818790100f81880380007' to parameter: 1
[junit] 19:06:23,094 DEBUG [loader.Loader] processing result set
[junit] 19:06:23,094 DEBUG [type.StringType] returning '4028815a00f818790100f81880380007' as column: guid
[junit] 19:06:23,094 DEBUG [loader.Loader] result row: 4028815a00f818790100f81880380007
[junit] 19:06:23,110 DEBUG [type.StringType] returning 'com.aebn.aia.core.domain.authorization.UserTimebankAdjustmentAuth
orization ' as column: type
[junit] 19:06:23,110 DEBUG [impl.BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
[junit] 19:06:23,110 DEBUG [impl.BatcherImpl] closing statement
[junit] 19:06:23,110 DEBUG [transaction.JDBCTransaction] rollback
[junit] 19:06:23,110 DEBUG [impl.SessionImpl] transaction completion
[junit] 19:06:23,110 DEBUG [transaction.JDBCTransaction] re-enabling autocommit
[junit] 19:06:23,110 DEBUG [impl.SessionImpl] closing session
[junit] 19:06:23,110 DEBUG [impl.SessionImpl] disconnecting session
[junit] 19:06:23,110 DEBUG [impl.SessionImpl] transaction completion
|