-->
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.  [ 7 posts ] 
Author Message
 Post subject: Strange ClassCastException while accessing result
PostPosted: Wed May 28, 2008 12:00 pm 
Newbie

Joined: Wed May 28, 2008 11:28 am
Posts: 6
Hi Everyone,

I am experiencing a strange probleme while configuring/testing Hibernate+Spring+JPA+Toplink

I am making this run on a Tomcat 5.5 server.

I am using the latest versions af all these frameworks.

I get a ClassCastException when casting the first element from my result list.
java.lang.ClassCastException: fr.b2i.vizada.soapServices.dataAccess.beans.Carte cannot be cast to fr.b2i.vizada.soapServices.dataAccess.beans.Carte


That's odd!

Help would be greatly appreciate!

My Spring configuration file :

Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

   <bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
      <property name="URL" value="jdbc:oracle:thin:@//xxx:1521/xxx" />
      <property name="user" value="xxx" />
      <property name="password" value="xxx" />
   </bean>

   <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
      <property name="dataSource" ref="dataSource" />
      <property name="jpaProperties">
         <props>
              <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
              <prop key="hibernate.hbm2ddl.auto">false</prop>
            </props>
      </property>
      <property name="jpaVendorAdapter">
         <bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter">
            <property name="showSql" value="true" />
            <property name="generateDdl" value="false" />
            <property name="databasePlatform" value="oracle.toplink.essentials.platform.database.HSQLPlatform" />
         </bean>
      </property>
      <property name="loadTimeWeaver">
         <bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver" />
      </property>
   </bean>

   <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
   
    <tx:annotation-driven />
   
    <bean id="carteDaoImpl" class="fr.b2i.vizada.soapServices.dataAccess.CarteDAOImpl"/>

</beans>



Here is my CarteDAOImpl java class :

Code:
package fr.b2i.vizada.soapServices.dataAccess;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.transaction.annotation.Transactional;

import fr.b2i.vizada.soapServices.dataAccess.beans.Carte;

@Transactional
public class CarteDAOImpl implements CarteDAO{
   
   private EntityManager entityManager;

    @PersistenceContext
    public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

   public List<Carte> selectAll() {
      //Getting only the first Carte object from the database for tests
      List list = entityManager.createQuery("Select object(p) FROM Carte p WHERE p.numcard='927451396149'").getResultList();
      System.out.println("count : "+list.size()); //This prints "count : 1"
      System.out.println(((Carte)list.get(0)).getNumcard()); //Here I get the ClassCastException !!
      return list;
   }
}


My Carte bean :
Code:
package fr.b2i.vizada.soapServices.dataAccess.beans;

import java.io.Serializable;
import java.sql.Date;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(schema="scratch")
public class Carte implements Serializable{
   
    //================== ATTRIBUTES =======================
   
   private static final long serialVersionUID = -1029166533902379914L;
   
   private String numcard;
    private String client;
    private String isp;
    private String service;
    private char active;
    private int credit;
    private Date dcreate;
    private Date dreload;
    private char udisplay;
    private int refresh;
    private int alarm;
    private int timeout;
    private Date dfirstuse;
    private String validite;
    private int type;
    private String serialn;
    private String source_maj;
    private int cost_indicator;
    private String currency;

    ...Accessors follow....



Just in case, here is the lib directory :

Code:
ant-1.6.5.jar
ant-antlr-1.6.5.jar
ant-junit-1.6.5.jar
ant-launcher-1.6.5.jar
antlr-2.7.6.jar
ant-swing-1.6.5.jar
aopalliance-1.0.jar
asm.jar
asm-attrs.jar
c3p0-0.9.1.jar
cglib-2.1.3.jar
checkstyle-all.jar
cleanimports.jar
commons-collections-2.1.1.jar
commons-logging-1.1.1.jar
concurrent-1.3.2.jar
cxf-2.1.jar
dom4j-1.6.1.jar
ehcache-1.2.3.jar
geronimo-activation_1.1_spec-1.0.2.jar
geronimo-annotation_1.0_spec-1.1.1.jar
geronimo-javamail_1.4_spec-1.3.jar
geronimo-ws-metadata_2.0_spec-1.1.2.jar
hibernate3.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
hibernate-entitymanager.jar
jaas.jar
jacc-1_0-fr.jar
javassist.jar
jaxb-api-2.1.jar
jaxb-impl-2.1.6.jar
jaxen-1.1.jar
jaxws-api-2.1-1.jar
jdom-1.0.jar
jgroups-2.2.8.jar
jta.jar
junit-3.8.1.jar
log4j-1.2.15.jar
neethi-2.0.4.jar
oracle-classes12.jar
oracle-ocrs12.jar
oracle-ojdbc14.jar
oracle-orai18n.jar
oscache-2.1.jar
proxool-0.8.3.jar
saaj-api-1.3.jar
saaj-impl-1.3.jar
spring.jar
stax-api-1.0.1.jar
swarmcache-1.0rc2.jar
syndiag2.jar
toplink-essentials.jar
versioncheck.jar
wsdl4j-1.6.1.jar
wstx-asl-3.2.4.jar
xml-apis.jar
xml-resolver-1.2.jar
XmlSchema-1.4.2.jar



Here is my trace log :

Code:
28 mai 2008 17:47:37 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: .
.
.
blablalbla
.
.
.
28 mai 2008 17:47:41 org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
28 mai 2008 17:47:42 org.apache.coyote.http11.Http11BaseProtocol start
INFO: Démarrage de Coyote HTTP/1.1 sur http-8282
28 mai 2008 17:47:42 org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
28 mai 2008 17:47:42 org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/16  config=null
28 mai 2008 17:47:42 org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
28 mai 2008 17:47:42 org.apache.catalina.startup.Catalina start
INFO: Server startup in 4406 ms
[TopLink Info]: 2008.05.28 05:47:51.593--ServerSession(4148925)--Thread(Thread[http-8282-Processor25,5,main])--TopLink, version: Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))
[TopLink Config]: 2008.05.28 05:47:51.609--ServerSession(4148925)--Connection(5868800)--Thread(Thread[http-8282-Processor25,5,main])--connecting(DatabaseLogin(
   platform=>HSQLPlatform
   user name=> ""
   connector=>JNDIConnector datasource name=>null
))
[TopLink Config]: 2008.05.28 05:47:52.125--ServerSession(4148925)--Connection(26914830)--Thread(Thread[http-8282-Processor25,5,main])--Connected: jdbc:oracle:thin:@//oradb2:1521/b2idb
   User: B2IT
   Database: Oracle  Version: Oracle Database 10g Enterprise Edition Release 10.1.0.5.0 - Production
With the Partitioning, Real Application Clusters and Data Mining options
   Driver: Oracle JDBC driver  Version: 10.1.0.2.0
[TopLink Config]: 2008.05.28 05:47:52.125--ServerSession(4148925)--Connection(10258369)--Thread(Thread[http-8282-Processor25,5,main])--connecting(DatabaseLogin(
   platform=>HSQLPlatform
   user name=> ""
   connector=>JNDIConnector datasource name=>null
))
[TopLink Config]: 2008.05.28 05:47:52.187--ServerSession(4148925)--Connection(9745176)--Thread(Thread[http-8282-Processor25,5,main])--Connected: jdbc:oracle:thin:@//oradb2:1521/b2idb
   User: B2IT
   Database: Oracle  Version: Oracle Database 10g Enterprise Edition Release 10.1.0.5.0 - Production
With the Partitioning, Real Application Clusters and Data Mining options
   Driver: Oracle JDBC driver  Version: 10.1.0.2.0
[TopLink Info]: 2008.05.28 05:47:52.265--ServerSession(4148925)--Thread(Thread[http-8282-Processor25,5,main])--file:/C:/Documents%20and%20Settings/ngarnier/workspace/VizadaSoapServices_model/WEB-INF/classes/-acme login successful
[TopLink Fine]: 2008.05.28 05:47:52.531--ClientSession(13868191)--Connection(13603674)--Thread(Thread[http-8282-Processor25,5,main])--SELECT NUMCARD, DCREATE, TYPE, DRELOAD, TIMEOUT, UDISPLAY, REFRESH, ISP, ALARM, CREDIT, DFIRSTUSE, CURRENCY, VALIDITE, ACTIVE, SERIALN, CLIENT, SOURCE_MAJ, SERVICE, COST_INDICATOR FROM scratch.CARTE WHERE (NUMCARD = ?)
   bind => [927451396149]
count : 1
28 mai 2008 17:47:52 org.apache.cxf.phase.PhaseInterceptorChain doIntercept
INFO: Application has thrown exception, unwinding now: java.lang.ClassCastException: fr.b2i.vizada.soapServices.dataAccess.beans.Carte cannot be cast to fr.b2i.vizada.soapServices.dataAccess.beans.Carte


Last edited by Nivco on Fri May 30, 2008 5:33 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed May 28, 2008 12:40 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
This is a class loading issue. See how many fr.b2i.vizada.soapServices.dataAccess.beans.Carte are in your class path. It might be included in two different jar files each of which is exposed to a different class loader.




Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 28, 2008 12:49 pm 
Newbie

Joined: Wed May 28, 2008 11:28 am
Posts: 6
That's kind of what I thought too... but I really don't know where it could be loaded a second time...

Maybe it is coming from the use of CXF (for SOAP publication of this method)... As this method is called from a soap request

I'll check this tomorrow...


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 29, 2008 4:42 am 
Newbie

Joined: Wed May 28, 2008 11:28 am
Posts: 6
This error is not comming from the soap call.
I took off all the SAOP stuff leaving only the code that I posted and the error still happend.

I am trying to check my ClassLoaders to find something...


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 29, 2008 5:10 am 
Newbie

Joined: Wed May 28, 2008 11:28 am
Posts: 6
I also looked in the Classpath and my "Carte" Class is defined only once.

ps : I used ManagementFactory.getRuntimeMXBean().getClassPath()
and ManagementFactory.getRuntimeMXBean().getBootClassPath() and then ispeced all the jar entries and all the Dir entries.

I still have to inspect classloaders to see if they woudl dynamically include the class...


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 29, 2008 5:41 am 
Newbie

Joined: Wed May 28, 2008 11:28 am
Posts: 6
OK I found the solution. It have alerady been posted here :
http://forum.springframework.org/archive/index.php/t-30781.html

A problem with the SimpleLoadClassWeaver not compatible with TopLink

The post offers several solutions.

Cheers! :D


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 30, 2008 5:31 am 
Newbie

Joined: Wed May 28, 2008 11:28 am
Posts: 6
So just for info I replaced the toplink JPA adaptor to an hibernate one. As it is much more compatible with the loadTimeWeaver classLoader. Here is my Spring config file that works :

Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
   
   <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
      <property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/>
      <property name="jdbcUrl" value="jdbc:oracle:thin:@//xxx:1521/xxx" />
      <property name="user" value="xxx" />
      <property name="password" value="xxx" />
      <property name="maxPoolSize" value="5" />
      <property name="minPoolSize" value="1" />
      <property name="maxIdleTime" value="5000" />
   </bean>

   <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
      <property name="persistenceXmlLocation"><value>WEB-INF/persistence.xml</value></property>
      <property name="dataSource" ref="dataSource" />
      <property name="jpaVendorAdapter">
         <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="showSql" value="true" />
            <property name="generateDdl" value="false" />
            <property name="databasePlatform" value="org.hibernate.dialect.Oracle9Dialect" />
         </bean>
      </property>
   </bean>

   <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
   
    <tx:annotation-driven />
   
    <bean id="carteDaoImpl" class="fr.b2i.vizada.soapServices.dataAccess.CarteDAOImpl"/>

       
</beans>


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