views:

467

answers:

2

Hello friends,

I am developing an application using SPRING 3.0.4, JPA 2, Hibernate 3.5.5.

I an trying an existing example given on link http://www.javacodegeeks.com/2010/05/jboss-42x-spring-3-jpa-hibernate.html.

only difference is that I am using latest versions of libraries and JBOSS server.

Following is list of my /WEB-INF/lib directory files

antlr-2.7.6.jar

aopalliance.jar

c3p0-0.9.1.jar

commons-collections-3.1.jar

commons-logging-1.1.1.jar

dom4j-1.6.1.jar

gwt-dev.jar

gwt-user.jar

hibernate3.jar

hibernate-jpa-2.0-api-1.0.0.Final.jar

hsqldb.jar

javassist-3.9.0.GA.jar

jta-1.1.jar

log4j-1.2.16.jar

org.springframework.aop-3.0.4.RELEASE.jar

org.springframework.asm-3.0.4.RELEASE.jar

org.springframework.aspects-3.0.4.RELEASE.jar

org.springframework.beans-3.0.4.RELEASE.jar

org.springframework.context.support-3.0.4.RELEASE.jar

org.springframework.context-3.0.4.RELEASE.jar

org.springframework.core-3.0.4.RELEASE.jar

org.springframework.expression-3.0.4.RELEASE.jar

org.springframework.instrument.tomcat-3.0.4.RELEASE.jar

org.springframework.instrument-3.0.4.RELEASE.jar

org.springframework.jdbc-3.0.4.RELEASE.jar

org.springframework.jms-3.0.4.RELEASE.jar

org.springframework.orm-3.0.4.RELEASE.jar

org.springframework.oxm-3.0.4.RELEASE.jar

org.springframework.test-3.0.4.RELEASE.jar

org.springframework.transaction-3.0.4.RELEASE.jar

org.springframework.web.portlet-3.0.4.RELEASE.jar

org.springframework.web.servlet-3.0.4.RELEASE.jar

org.springframework.web.struts-3.0.4.RELEASE.jar

org.springframework.web-3.0.4.RELEASE.jar

slf4j-api-1.5.8.jar

slf4j-log4j12-1.6.1.jar

spring4gwt-0.0.1.jar

Following is my /WEB-INF/web.xml file

<?xml version="1.0" encoding="UTF-8"?>

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

<!-- Servlets -->

<servlet>
    <servlet-name>springGwtRemoteServiceServlet</servlet-name>
    <servlet-class>org.spring4gwt.server.SpringGwtRemoteServiceServlet
</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>springGwtRemoteServiceServlet</servlet-name>
    <url-pattern>/gwtspring/springGwtServices/*</url-pattern>
</servlet-mapping>

<!-- Default page to serve -->
<welcome-file-list>
    <welcome-file>GWTSpring.html</welcome-file>
</welcome-file-list>

Following is my /WEB-INF/applicationContext.xml file

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"&gt;

<context:component-scan base-package="com.javacodegeeks.gwtspring" />

<task:annotation-driven executor="myExecutor" scheduler="myScheduler" />

<task:executor id="myExecutor" pool-size="5" />

<task:scheduler id="myScheduler" pool-size="10" />

<tx:annotation-driven />

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="MyPersistenceUnit" />
</bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

Following is my /src/resources/META-INF/petsistence.xml file

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">

<persistence-unit name="MyPersistenceUnit" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <non-jta-data-source>java:/gwtDS</non-jta-data-source>

    <properties>
        <property name="hibernate.hbm2ddl.auto" value="update" />
        <property name="hibernate.show_sql" value="false" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
        <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver" />
        <property name="hibernate.connection.url" value="jdbc:hsqldb:mem:salvation" />
        <property name="hibernate.connection.username" value="sa" />
        <property name="hibernate.connection.password" value="" />

        <property name="hibernate.c3p0.min_size" value="5" />
        <property name="hibernate.c3p0.max_size" value="20" />
        <property name="hibernate.c3p0.timeout" value="300" />
        <property name="hibernate.c3p0.max_statements" value="50" />
        <property name="hibernate.c3p0.idle_test_period" value="3000" />

    </properties>

</persistence-unit>

Now when I am trying to complile it using JBOSS server it gives me following error

11:34:17,828 INFO [ServerImpl] JBoss (Microcontainer) [5.1.0.GA (build: SVNTag=JBoss_5_1_0_GA date=200905221053)] Started in 19s:985ms 11:34:28,437 INFO [PersistenceUnitDeployment] Starting persistence unit persistence.unit:unitName=#MyPersistenceUnit 11:34:29,046 ERROR [AbstractKernelController] Error installing to Start: name=persistence.unit:unitName=#MyPersistenceUnit state=Create java.lang.ClassCastException: org.hibernate.ejb.HibernatePersistence cannot be cast to javax.persistence.spi.PersistenceProvider at org.jboss.jpa.deployment.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:300) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:59) at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:150) at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66) at org.jboss.kernel.plugins.dependency.KernelControllerContextAction$JoinpointDispatchWrapper.execute(KernelControllerContextAction.java:241) at org.jboss.kernel.plugins.dependency.ExecutionWrapper.execute(ExecutionWrapper.java:47) at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchExecutionWrapper(KernelControllerContextAction.java:109) at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchJoinPoint(KernelControllerContextAction.java:70) at org.jboss.kernel.plugins.dependency.LifecycleAction.installActionInternal(LifecycleAction.java:221) at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:54) at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:42) at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62) at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71) at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51) at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348) at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631) at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934) at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082) at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984) at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:774) at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:540) at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(BeanMetaDataDeployer.java:121) at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(BeanMetaDataDeployer.java:51) at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62) at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50) at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171) at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439) at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157) at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1178) at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098) at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348) at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631) at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934) at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082) at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984) at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822) at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553) at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781) at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:702) at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117) at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:362) at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:255) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619)

Can anyone here help me to solve the problem.

Please let me know if you need anything else from me.

Thanks.

+1  A: 

I guess you don't need hibernate-jpa-2.0-api-1.0.0.Final.jar in /WEB-INF/lib, since JBoss have its own set of JPA classes.

So, you have two sets of JPA classes loaded by different classloaders, and these classes can't be casted to each other.

axtavt
Exactly. Your JBoss has it's own JPA implementation.
seanizer
Hello friends, Thanks for the answer but if I remove hibernate-jpa-2.0-api-1.0.0.Final.jar in /WEB-INF/lib it gives me following error java.lang.ClassNotFoundException: javax.persistence.spi.ProviderUtil from BaseClassLoader@1b429{VFSClassLoaderPolicy@1daf1cd{name=vfsfile:/E:/workspace/eclipse/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_5.1_Server/deploy/GWTSpring.war/
amar4kintu
@amar4kintu: Looks at the Pascal Thivent's answer, it's more appropriate.
axtavt
+1  A: 

I personally never succeeded using JPA 2.0 with JBoss 5.1.x (due to too tight integration with JPA 1.0) although it seems possible with JBoss 4.2.

My suggestion would be to either use JBoss 6.0 M4 (at the time of writing this) and to remove all the hibernate related JARs from the webapp:

  • antlr-2.7.6.jar
  • commons-collections-3.1.jar
  • dom4j-1.6.1.jar
  • hibernate3.jar
  • hibernate-jpa-2.0-api-1.0.0.Final.jar
  • javassist-3.9.0.GA.jar
  • jta-1.1.jar

Or to simply use Tomcat (and deploy your webapp as is) since you're not using anything from JBoss.

See also

Pascal Thivent
Pascal, I tried using JBOSS 6.0 M4 but it gives error- Caused by: java.lang.LinkageError: loader constraint violation in interface itable initialization: when resolving method "org.springframework.util.xml.XMLEventStreamReader.getName()Ljavax/xml/namespace/QName;" the class loader (instance of org/jboss/classloader/spi/base/BaseClassLoader) of the current class, org/springframework/util/xml/XMLEventStreamReader, and the class loader (instance of <bootloader>) for interface javax/xml/stream/XMLStreamReader have different Class objects for the type javax/xml/namespace/QName used in the signature
amar4kintu