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