-->
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: java.lang.ClassCastException with lazy loading class
PostPosted: Wed Jun 14, 2006 12:07 pm 
Newbie

Joined: Wed Jun 07, 2006 11:15 am
Posts: 2
Hi all,

I am using Spring with Hibernate 3.1. An ClassCastException is throw in the follwoing code:
HibernateTemplate temp = getHibernateTemplate();
Object load = temp.load(FormSubmission.class, submissionId);
return (FormSubmissionInterface) load; (Exeption occure this line)

In debug mode, I can see the load=FormSubmissonInterface$$EnhanceByCGLIB$$



My mapping file is:


<class name="com.abc.FormSubmission"
table="form_submission"
dynamic-update="false"
dynamic-insert="false"
proxy="com.abc.FormSubmissionInterface"
>
<id name="id" column="id" type="java.lang.Long">
<generator class="native"></generator>
</id>
<property name="submissionDate" type="java.util.Date" update="true" insert="true" access="property" column="submission_date"/>
</class>


I assume hibernate will generate a class implements the interface. How can the casting throw an exception??
Any help much appriciated !


Top
 Profile  
 
 Post subject: Re: java.lang.ClassCastException with lazy loading class
PostPosted: Wed Jun 14, 2006 4:00 pm 
Beginner
Beginner

Joined: Tue May 02, 2006 10:04 am
Posts: 29
You should not declare load as an Object. Instead, declare it as an interface:

FormSubmissionInterface load = temp.load(FormSubmission.class, submissionId);


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 4:36 am 
Newbie

Joined: Wed Jun 07, 2006 11:15 am
Posts: 2
Hi imchi,

HIbernateTemplate.load actually return a Object type value.
See here:
http://www.springframework.org/docs/api ... rializable)


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.