• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

WrongClassException on joined-subclass

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My question is very similar to the following one issue
http://opensource2.atlassian.com/projects/hibernate/browse/HHH-606

And the stauts for the bug is closed, so I am not sure whether this has been fixed in the hibernate new release.

Thanks a lot.

Here are the details

Hibernate version:
Hibernate 3.0.5

Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class
name="model.environment.impacts.measurement.EnvironmentalMeasurement"
table="ENV_MEASUREMENT"
>
<id
name="id"
column="ID"
type="java.lang.Integer"
unsaved-value="0"
>
<generator class="native">

</generator>
</id>
<discriminator
column="TYPE"
/>
<property
name="value"
type="java.lang.Float"
column="VALUE"
/>
<property
name="date"
type="java.util.Date"
column="CONSUMPTION_DATE"
/>
<set
name="children"
lazy="false"
inverse="true"
cascade="save-update"
sort="unsorted"
>
<key
column="PARENT_ID"
>
</key>

<one-to-many
class="model.environment.impacts.measurement.EnvironmentalMeasurement"
/>

</set>
<many-to-one
name="parent"
class="model.environment.impacts.measurement.EnvironmentalMeasurement"
cascade="save-update"
outer-join="auto"
column="PARENT_ID"
/>
<subclass
name="model.environment.impacts.measurement.BatteryReplacement"
>

</subclass>
<subclass
name="model.environment.impacts.measurement.ElectricHeatingConsumption"
>
</subclass>
<subclass
name="model.environment.impacts.measurement.LightSourceReplacement"
>
<property
name="replacementType"
type="java.lang.String"
column="REPLACEMENT_TYPE"
length="4000"
/>

</subclass>
<subclass
name="model.environment.impacts.measurement.DieselEngineExhaustGases"
>

</subclass>
<subclass
name="model.environment.impacts.measurement.BathroomWaterConsumption"
>
</subclass>
<subclass
name="model.environment.impacts.measurement.CableReplacement"
>
<property
name="a1CU"
type="int"
column="A1CU"
/>

<property
name="length"
type="java.lang.Float"
column="CABLE_LENGTH"
/>

</subclass>
<subclass
name="environment.impacts.measurement.RecipientCleaningConsumption"
>

</subclass>
<subclass
name="model.environment.impacts.measurement.PowerConsumption"
>


</subclass>
<subclass
name="model.environment.impacts.measurement.PlantCleaningConsumption"
>

</subclass>
<subclass
name="model.environment.impacts.measurement.FittingReplacement"
>
<property
name="replacementType"
type="java.lang.String"
column="REPLACEMENT_TYPE"
length="256"
/>
</subclass>
<subclass
name="model.environment.impacts.measurement.LightingConsumption"
>

</subclass>
<subclass
name="model.environment.impacts.measurement.HydrogenConcentration"
>
</subclass>
<subclass
name="model.environment.impacts.measurement.ComponentReplacement"
>
<property
name="replacementType"
type="java.lang.String"
column="REPLACEMENT_TYPE"
length="256"
/>

</subclass>
<subclass
name="model.environment.impacts.measurement.TransformerLossConsumption"
>
</subclass>

<subclass
name="model.environment.impacts.measurement.PumpRoomGases"
>
</subclass>
<subclass
name="model.environment.impacts.measurement.PumpEngineConsumption"
>


</class>

</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():

public EnvironmentalImpact findById(Integer id)
{

EnvironmentalImpact result = null;
try
{
String query = "from EnvironmentalImpact where id = :getId";
result = (EnvironmentalImpact)HibernateSession.getSession()
.createQuery(query)
.setInteger("getId", id.intValue())
.uniqueResult();
}
catch (Exception e)
{
e.printStackTrace();
}

return result;
}

Full stack trace of any exception that occurs:

org.hibernate.WrongClassException: Object with id: 4 was not of the specified subclass: model.environment.impacts.measurement.TransformerLossConsumption (loaded object was of wrong class)

at org.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:890)

at org.hibernate.loader.Loader.getRow(Loader.java:846)

at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:305)

at org.hibernate.loader.Loader.doQuery(Loader.java:412)

at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)

at org.hibernate.loader.Loader.loadCollection(Loader.java:1434)

at org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:111)

at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488)

at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)

at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1430)

at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:280)

at org.hibernate.engine.PersistenceContext.initializeNonLazyCollections(PersistenceContext.java:796)

at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)

at org.hibernate.loader.Loader.loadEntity(Loader.java:1345)

at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:116)

at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:101)

at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2471)

at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:351)

at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:332)

at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:113)

at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:75)

at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:643)

at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:59)

at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)

at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)



Name and version of the database you are using:
MySql

The generated SQL (show_sql=true):
CREATE TABLE `env_measurement` (
`ID` int(11) NOT NULL auto_increment,
`TYPE` varchar(255) NOT NULL default '',
`VALUE` float default NULL,
`CONSUMPTION_DATE` datetime default NULL,
`PARENT_ID` int(11) default NULL,
`REPLACEMENT_TYPE` text,
`A1CU` int(11) default NULL,
`CABLE_LENGTH` float default NULL,
`EX_EFFECTS_ID` int(11) default NULL,
`INT_EFFECTS_ID` int(11) default NULL,
`RES_EFFECTS_ID` int(11) default NULL,
PRIMARY KEY (`ID`),
KEY `FK18EE0F2A724B8938` (`INT_EFFECTS_ID`),
KEY `FK18EE0F2A70575576` (`RES_EFFECTS_ID`),
KEY `FK18EE0F2AFB902115` (`PARENT_ID`),
KEY `FK18EE0F2AF5BB6926` (`EX_EFFECTS_ID`),
CONSTRAINT `FK18EE0F2AF5BB6926` FOREIGN KEY (`EX_EFFECTS_ID`) REFERENCES `env_external_effects` (`ID`),
CONSTRAINT `FK18EE0F2A70575576` FOREIGN KEY (`RES_EFFECTS_ID`) REFERENCES `env_resource_effect` (`ID`),
CONSTRAINT `FK18EE0F2A724B8938` FOREIGN KEY (`INT_EFFECTS_ID`) REFERENCES `env_internal_effects` (`ID`),
CONSTRAINT `FK18EE0F2AFB902115` FOREIGN KEY (`PARENT_ID`) REFERENCES `env_measurement` (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1


Debug level Hibernate log excerpt:


17:29:05,680 ERROR DispatchAction:95 - showList error,
org.hibernate.WrongClassException: Object with id: 4 was not of the specified subclass: model.environment.impacts.measurement.TransformerLossConsumption (loaded object was of wrong class)
at org.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:890)
at org.hibernate.loader.Loader.getRow(Loader.java:846)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:305)
at org.hibernate.loader.Loader.doQuery(Loader.java:412)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1434)
at org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:111)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1430)
at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:280)
at org.hibernate.engine.PersistenceContext.initializeNonLazyCollections(PersistenceContext.java:796)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1345)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:116)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:101)
at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2471)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:351)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:332)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:113)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:75)
at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:643)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:59)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am stuck with the same problem Oliver, please let me know if you find any solution. I will post a solution if I find one.
 
This will take every ounce of my mental strength! All for a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic