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