-->
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.  [ 3 posts ] 
Author Message
 Post subject: ClassCastException on EntityType when in DEBUG mode only!
PostPosted: Sat Jul 23, 2005 1:20 pm 
Beginner
Beginner

Joined: Fri Feb 20, 2004 6:15 pm
Posts: 38
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()


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 02, 2005 5:14 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Just to say that I have the same problem.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 02, 2005 9:20 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
I dig into the code to find what's going on in my case

The problem is mine (this is often the case).

In my case, I do a query and set an incorrect param type for one of the params of the query. Whithout the debug mode everything is fine because the type is compatible with the entity I pass as a parameter, both are entities with a primary key called oid.

HTH

Seb


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.