I'm getting a ClassCastException when running in log4j DEBUG mode for Hibernate. However, if I run in non-DEBUG mode, like WARN, then I do not get this error at all. I've tried this out on both 3.0.5 and 3.1b1.
I tried looking at the EntityType code but I'm not sure why Hibernate thinks it's an error if isEmbeddedInXML is set.
Hibernate version:
3.0.5 (and 3.1b1)
Mapping documents:
<hibernate-mapping>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="edu.uiuc.cs411.rentalproperty.domain.Property"
table="property">
<id name="propertyId" type="integer">
<column name="property_id" />
<generator class="native" />
</id>
<many-to-one name="manager"
class="edu.uiuc.cs411.rentalproperty.domain.Manager">
<column name="manager_id" not-null="true" />
</many-to-one>
<property name="area" type="integer">
<column name="area" />
</property>
<set name="leases" inverse="true" order-by="start_date asc" cascade="all">
<key>
<column name="property_id" not-null="true" />
</key>
<one-to-many
class="edu.uiuc.cs411.rentalproperty.domain.Lease" />
</set>
<set name="expenses" inverse="true" order-by="date asc" cascade="all">
<key>
<column name="property_id" not-null="true" />
</key>
<one-to-many
class="edu.uiuc.cs411.rentalproperty.domain.Expense" />
</set>
<joined-subclass
name="edu.uiuc.cs411.rentalproperty.domain.Building"
table="building">
<key column="property_id" />
<many-to-one name="zipcode"
class="edu.uiuc.cs411.rentalproperty.domain.Zipcode">
<column name="zip" precision="5" scale="0"
not-null="true" />
</many-to-one>
<property name="streetAddress" type="string">
<column name="street_address" length="40"
not-null="true" />
</property>
<property name="floors" type="short">
<column name="floors" not-null="true" />
</property>
<set name="houses" inverse="true">
<key>
<column name="property_id" not-null="true"
unique="true" />
</key>
<one-to-many
class="edu.uiuc.cs411.rentalproperty.domain.House" />
</set>
<set name="apartments" inverse="true">
<key>
<column name="building_id" not-null="true" />
</key>
<one-to-many
class="edu.uiuc.cs411.rentalproperty.domain.Apartment" />
</set>
<set name="features" inverse="true" cascade="all">
<key>
<column name="property_id" not-null="true" />
</key>
<one-to-many
class="edu.uiuc.cs411.rentalproperty.domain.Feature" />
</set>
<joined-subclass name="edu.uiuc.cs411.rentalproperty.domain.House" table="house">
<key column="property_id"/>
</joined-subclass>
</joined-subclass>
<joined-subclass
name="edu.uiuc.cs411.rentalproperty.domain.Apartment"
table="apartment">
<key column="property_id" />
<many-to-one name="building"
class="edu.uiuc.cs411.rentalproperty.domain.Building">
<column name="building_id" not-null="true" />
</many-to-one>
<property name="unitNumber" type="string">
<column name="unit_number" length="10" not-null="true" />
</property>
<property name="level" type="short">
<column name="level" not-null="true" />
</property>
</joined-subclass>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Query currentLeaseQuery = aSession
.createQuery("from Lease lease "
+ "where lease.property in (:properties) and lease.startDate <= current_date() and lease.endDate >= current_date()");
currentLeaseQuery.setParameterList("properties", propertyList);
List currentLeases = currentLeaseQuery.list();
Full stack trace of any exception that occurs:
java.lang.ClassCastException: edu.uiuc.cs411.rentalproperty.domain.Apartment
org.hibernate.type.EntityType.toLoggableString(EntityType.java:145)
org.hibernate.pretty.Printer.toString(Printer.java:76)
org.hibernate.engine.QueryParameters.traceParameters(QueryParameters.java:224)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:830)
org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
Name and version of the database you are using:
MySql 4.x
The generated SQL (show_sql=true):
can't see it because the error happens
Debug level Hibernate log excerpt:
http-8080-Processor25 06:13:30 org.hibernate.jdbc.AbstractBatcher closePreparedStatement DEBUG line 416 -closing statement
http-8080-Processor25 06:13:30 org.hibernate.loader.Loader initializeEntitiesAndCollections DEBUG line 528 -total objects hydrated: 2
http-8080-Processor25 06:13:30 org.hibernate.engine.TwoPhaseLoad initializeEntity DEBUG line 96 -resolving associations for [edu.uiuc.cs411.rentalproperty.domain.Building#1]
http-8080-Processor25 06:13:30 org.hibernate.event.def.DefaultLoadEventListener proxyOrLoad DEBUG line 143 -loading entity: [edu.uiuc.cs411.rentalproperty.domain.Manager#1]
http-8080-Processor25 06:13:30 org.hibernate.event.def.DefaultLoadEventListener createProxyIfNecessary DEBUG line 216 -creating new proxy for entity
http-8080-Processor25 06:13:30 org.hibernate.engine.CollectionLoadContext getLoadingCollection DEBUG line 141 -creating collection wrapper:[edu.uiuc.cs411.rentalproperty.domain.Property.leases#1]
http-8080-Processor25 06:13:30 org.hibernate.engine.CollectionLoadContext getLoadingCollection DEBUG line 141 -creating collection wrapper:[edu.uiuc.cs411.rentalproperty.domain.Property.expenses#1]
http-8080-Processor25 06:13:30 org.hibernate.event.def.DefaultLoadEventListener proxyOrLoad DEBUG line 143 -loading entity: [edu.uiuc.cs411.rentalproperty.domain.Zipcode#90210]
http-8080-Processor25 06:13:30 org.hibernate.event.def.DefaultLoadEventListener createProxyIfNecessary DEBUG line 216 -creating new proxy for entity
http-8080-Processor25 06:13:30 org.hibernate.engine.CollectionLoadContext getLoadingCollection DEBUG line 141 -creating collection wrapper:[edu.uiuc.cs411.rentalproperty.domain.Building.houses#1]
http-8080-Processor25 06:13:30 org.hibernate.engine.CollectionLoadContext getLoadingCollection DEBUG line 141 -creating collection wrapper:[edu.uiuc.cs411.rentalproperty.domain.Building.apartments#1]
http-8080-Processor25 06:13:30 org.hibernate.engine.CollectionLoadContext getLoadingCollection DEBUG line 141 -creating collection wrapper:[edu.uiuc.cs411.rentalproperty.domain.Building.features#1]
http-8080-Processor25 06:13:30 org.hibernate.engine.TwoPhaseLoad initializeEntity DEBUG line 167 -done materializing entity [edu.uiuc.cs411.rentalproperty.domain.Building#1]
http-8080-Processor25 06:13:30 org.hibernate.engine.TwoPhaseLoad initializeEntity DEBUG line 96 -resolving associations for [edu.uiuc.cs411.rentalproperty.domain.Apartment#2]
http-8080-Processor25 06:13:30 org.hibernate.event.def.DefaultLoadEventListener proxyOrLoad DEBUG line 143 -loading entity: [edu.uiuc.cs411.rentalproperty.domain.Manager#1]
http-8080-Processor25 06:13:30 org.hibernate.event.def.DefaultLoadEventListener returnNarrowedProxy DEBUG line 186 -entity proxy found in session cache
http-8080-Processor25 06:13:30 org.hibernate.engine.CollectionLoadContext getLoadingCollection DEBUG line 141 -creating collection wrapper:[edu.uiuc.cs411.rentalproperty.domain.Property.leases#2]
http-8080-Processor25 06:13:30 org.hibernate.engine.CollectionLoadContext getLoadingCollection DEBUG line 141 -creating collection wrapper:[edu.uiuc.cs411.rentalproperty.domain.Property.expenses#2]
http-8080-Processor25 06:13:30 org.hibernate.event.def.DefaultLoadEventListener proxyOrLoad DEBUG line 143 -loading entity: [edu.uiuc.cs411.rentalproperty.domain.Building#1]
http-8080-Processor25 06:13:30 org.hibernate.event.def.DefaultLoadEventListener createProxyIfNecessary DEBUG line 208 -entity found in session cache
http-8080-Processor25 06:13:30 org.hibernate.engine.TwoPhaseLoad initializeEntity DEBUG line 167 -done materializing entity [edu.uiuc.cs411.rentalproperty.domain.Apartment#2]
http-8080-Processor25 06:13:30 org.hibernate.engine.PersistenceContext initializeNonLazyCollections DEBUG line 789 -initializing non-lazy collections
http-8080-Processor25 06:13:30 org.hibernate.impl.SessionImpl list DEBUG line 829 -find: from Lease lease where lease.property in (:properties0_, :properties1_) and lease.startDate <= current_date() and lease.endDate >= current_date()
|