-->
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.  [ 8 posts ] 
Author Message
 Post subject: ClassCastException
PostPosted: Thu Sep 01, 2005 4:30 pm 
Newbie

Joined: Mon Aug 15, 2005 11:16 am
Posts: 14
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

I have a very simple mapping for a database view (See below.) And I created a simple query to retrieve the object. I can see the object in the Eclipse debug, but whenever it is casted to the WebUser POJO object, it generates ClassCastException exception. Since the object has no collection, no proxy, and has been initiliazed, why it cannot be casted to WebUser object.

The WebUser POJO is created by hbm2java and I didnot change anything to it. (I am using second level cache.)

Thanks,




SQ


[b]Hibernate version:[/b]
Hibernate 3.05 with JBoss 4.0.2

[b]Mapping documents:[/b]
<class name="com.tsh.customerBook.model.WebUser" table="V_WEB_USER" schema="JAVA" mutable="false" >
<id name="webUserOid" type="long" >
<column name="WEB_USER_OID"
precision="10"
scale="0" />
<generator class="assigned" />
</id>
<property name="userId" type="string">
<column name="USER_ID" length="50" />
</property>
<property name="firstName" type="string">
<column name="FIRST_NAME" length="50" />
</property>
....
[b]Code between sessionFactory.openSession() and session.close():[/b]
Session session = HibernateUtil.getSession();
HibernateUtil.beginTransaction();
Query query = session.createQuery("from WebUser where userId = :username");
query.setString("username", username);
WebUser webUser = (WebUser)query.uniqueResult();
if(webUser != null && hashedPass.equalsIgnoreCase(webUser.getPassword())) {
log.info(classMethod + " Successfully verify user: " + username);
flag = true;
}
HibernateUtil.commitTransaction();
[b]Full stack trace of any exception that occurs:[/b]
15:05:09,918 ERROR [TSHSecurityRealm] com.tsh.customerBook.security.TSHSecurityRealm.booleanAuthenticatejava.lang.ClassCastException: com.tsh.customerBook.model.WebUser
15:05:09,918 INFO [STDOUT] java.lang.ClassCastException: com.tsh.customerBook.model.WebUser
15:05:09,918 INFO [STDOUT] at com.tsh.customerBook.security.TSHSecurityRealm.booleanAuthenticate(TSHSecurityRealm.java:58)
15:05:09,918 INFO [STDOUT] at com.tsh.customerBook.security.TSHSecurityRealm.authenticate(TSHSecurityRealm.java:109)
15:05:09,918 INFO [STDOUT] at org.securityfilter.authenticator.FormAuthenticator.processLogin(FormAuthenticator.java:179)
15:05:09,918 INFO [STDOUT] at org.securityfilter.filter.SecurityFilter.doFilter(SecurityFilter.java:138)
15:05:09,918 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
15:05:09,918 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
15:05:09,918 INFO [STDOUT] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
15:05:09,918 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
15:05:09,918 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
15:05:09,918 INFO [STDOUT] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
15:05:09,918 INFO [STDOUT] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
15:05:09,918 INFO [STDOUT] at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
15:05:09,918 INFO [STDOUT] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
15:05:09,918 INFO [STDOUT] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
15:05:09,918 INFO [STDOUT] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
15:05:09,918 INFO [STDOUT] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
15:05:09,918 INFO [STDOUT] at org.apache.catalina.valves.FastCommonAccessLogValve.invoke(FastCommonAccessLogValve.java:481)
15:05:09,918 INFO [STDOUT] at org.apache.catalina.valves.RequestDumperValve.invoke(RequestDumperValve.java:150)
15:05:09,918 INFO [STDOUT] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
15:05:09,918 INFO [STDOUT] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
15:05:09,918 INFO [STDOUT] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
15:05:09,918 INFO [STDOUT] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
15:05:09,918 INFO [STDOUT] at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
15:05:09,918 INFO [STDOUT] at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
15:05:09,918 INFO [STDOUT] at java.lang.Thread.run(Thread.java:595)
[b]Name and version of the database you are using:[/b]
Oracle 9i
[b]The generated SQL (show_sql=true):[/b]

[b]Debug level Hibernate log excerpt:[/b]

15:05:09,199 DEBUG [StringType] returning '563 577 4270' as column: PHONE17_
15:05:09,199 DEBUG [StringType] returning '1199dba5c3c0398fe0f7d648a789fc5c' as column: CONFIRM14_17_
15:05:09,652 DEBUG [BigDecimalType] returning '1' as column: IS15_17_
15:05:09,652 DEBUG [StringType] returning 'Yes' as column: REQUEST16_17_
15:05:09,652 DEBUG [StringType] returning null as column: DELETE17_17_
15:05:09,668 DEBUG [DateType] returning '29 August 2005' as column: LAST18_17_
15:05:09,668 DEBUG [StringType] returning '139.177.224.128' as column: REMOTE19_17_
15:05:09,668 DEBUG [DateType] returning null as column: LAST20_17_
15:05:09,668 DEBUG [Loader] done processing result set (1 rows)
15:05:09,668 DEBUG [AbstractBatcher] about to close ResultSet (open ResultSets: 1, globally: 1)
15:05:09,887 DEBUG [AbstractBatcher] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
15:05:09,887 DEBUG [AbstractBatcher] closing statement
15:05:09,887 DEBUG [Loader] total objects hydrated: 1
15:05:09,887 DEBUG [TwoPhaseLoad] resolving associations for [com.tsh.customerBook.model.WebUser#11406]
15:05:09,902 DEBUG [TwoPhaseLoad] done materializing entity [com.tsh.customerBook.model.WebUser#11406]
15:05:09,902 DEBUG [PersistenceContext] initializing non-lazy collections
15:05:09,902 DEBUG [HibernateUtil] com.tsh.customerBook.persistence.HibernateUtil.rollbackTransaction Tyring to rollback database transaction of this thread.
15:05:09,902 DEBUG [JTATransaction] rollback
15:05:09,902 DEBUG [CacheSynchronization] transaction after completion callback, status: 4
15:05:09,902 DEBUG [JDBCContext] after transaction completion
15:05:09,902 DEBUG [SessionImpl] after transaction completion
15:05:09,902 DEBUG [CacheSynchronization] automatically closing session
15:05:09,902 DEBUG [SessionImpl] automatically closing session
15:05:09,902 DEBUG [SessionImpl] closing session
15:05:09,902 DEBUG [ConnectionManager] closing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
15:05:09,918 DEBUG [JDBCContext] after transaction completion
15:05:09,918 DEBUG [SessionImpl] after transaction completion
15:05:09,918 DEBUG [JTATransaction] Rolled back JTA UserTransaction
15:05:09,918 DEBUG [TSHSecurityRealm] com.tsh.customerBook.security.TSHSecurityRealm.booleanAuthenticate Cannot verify username and password for user: user


Top
 Profile  
 
 Post subject: Re: ClassCastException
PostPosted: Thu Sep 01, 2005 4:34 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
What is this method doing at line 58 ?

com.tsh.customerBook.security.TSHSecurityRealm.booleanAuthenticate()

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject: ClassCastException
PostPosted: Thu Sep 01, 2005 4:39 pm 
Newbie

Joined: Mon Aug 15, 2005 11:16 am
Posts: 14
Line 58: WebUser webUser = (WebUser)query.uniqueResult();


Top
 Profile  
 
 Post subject: Re: ClassCastException
PostPosted: Thu Sep 01, 2005 4:41 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
sqian99 wrote:
Line 58: WebUser webUser = (WebUser)query.uniqueResult();


I would suggest using your debugger and finding out what it's actually returning. Are you using polymorphism ?

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject: ClassCastException
PostPosted: Thu Sep 01, 2005 5:05 pm 
Newbie

Joined: Mon Aug 15, 2005 11:16 am
Posts: 14
No, I am not using polymorphism. It is a very simple mapping for a database view.

when I devide the line 58 into

Object o = query.uniqueResult();
WebUser webUser = (WebUser)o;

I can clearly see the WebUser object o and all its fields in the debugger, but whenever the control comes to WebUser webUser = (WebUser)o; the exception occures.


Top
 Profile  
 
 Post subject: Re: ClassCastException
PostPosted: Thu Sep 01, 2005 5:06 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
sqian99 wrote:
No, I am not using polymorphism. It is a very simple mapping for a database view.

when I devide the line 58 into

Object o = query.uniqueResult();
WebUser webUser = (WebUser)o;

I can clearly see the WebUser object o and all its fields in the debugger, but whenever the control comes to WebUser webUser = (WebUser)o; the exception occures.


I can't think of anything else unless you have 2 WebUser classes in different packages.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject: ClassCastException
PostPosted: Thu Sep 01, 2005 5:33 pm 
Newbie

Joined: Mon Aug 15, 2005 11:16 am
Posts: 14
No, I checked carefully, no duplicate WebUser class files.


Top
 Profile  
 
 Post subject: ClassCastException
PostPosted: Fri Sep 02, 2005 12:40 pm 
Newbie

Joined: Mon Aug 15, 2005 11:16 am
Posts: 14
After digging into the JBoss forum about the topic, and doing some changes about the packaging and classloading config. I get it fixed.

If you are using JBoss 4.0.2 and have other ClassCastException issues, check the forum and it is most likely a classloading and packaging issue.


Thanks,


SQ


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