Announcement Announcement Module
Collapse
No announcement yet.
org.hibernate.ejb.HibernatePersistence cannot be cast to javax.persistence.spi.Persis Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • org.hibernate.ejb.HibernatePersistence cannot be cast to javax.persistence.spi.Persis

    Hello friends,

    I am trying Spring with JPA using JBOSS 5.1 server.

    Following is my WEB-INF/lib directory

    appserv-jstl.jar
    hibernate3.jar
    hibernate-jpa-2.0-api-1.0.0.Final.jar
    hibernate-validator.jar
    hsqldb.jar
    javaee.jar
    org.springframework.asm-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.jdbc-3.0.4.RELEASE.jar
    org.springframework.orm-3.0.4.RELEASE.jar
    org.springframework.transaction-3.0.4.RELEASE.jar
    org.springframework.web.servlet-3.0.4.RELEASE.jar
    org.springframework.web-3.0.4.RELEASE.jar



    Following is my WEB-INF/web.xml file

    Code:
    <?xml version="1.0"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
        version="2.4">
    
      <display-name>Spring2JPA</display-name>
      <description>Spring JPA Demo Application</description>
      	<!--
    	  - Key of the system property that should specify the root directory of this
    	  - web app. Applied by WebAppRootListener or Log4jConfigListener.
    	  -->
      <context-param>
        <param-name>webAppRootKey</param-name>
        <param-value>spring2jps.root</param-value>
      </context-param>
    
      	<!--
    	  - Location of the Log4J config file, for initialization and refresh checks.
    	  - Applied by Log4jConfigListener.
    	  -->
      <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>/WEB-INF/log4j.properties</param-value>
      </context-param>
    
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext-jpa.xml</param-value>
      </context-param>
    
      <!--
       - Loads the root application context of this web app at startup, see
       - contextConfigLocation above
      -->
      <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
    
      <servlet>
        <description>Spring MVC Dispatcher Servlet</description>
        <display-name>DispatcherServlet</display-name>
        <servlet-name>spring2jpa</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
    
      <servlet-mapping>
        <servlet-name>spring2jpa</servlet-name>
        <url-pattern>*.htm</url-pattern>
      </servlet-mapping>
    
      <welcome-file-list>
        <welcome-file>home.htm</welcome-file>
      </welcome-file-list>
    
      <error-page>
        <exception-type>java.lang.Exception</exception-type>
        <!-- Displays a stack trace -->
        <location>/uncaughtException.jsp</location>
      </error-page>
    </web-app>


    Following is my WEB-INF/spring2jpa-servlet.xml 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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
      
      <bean id="mainController" class="com.abcseo.mvc.MainController">
        <property name="customerDAO">
          <ref bean="customerDAO"/>
        </property>
      </bean>
      
      <bean name="custDetailsController" class="com.abcseo.mvc.CustDetailsController">
        <property name="customerDAO">
          <ref bean="customerDAO"/>
        </property>
      </bean>
      
      <bean id="controllermap" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
        <props>
          <prop key="/home.htm">mainController</prop>
          <prop key="/custdet.htm">custDetailsController</prop>
        </props>
        </property>
      </bean>
      
      <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/jsp/"/>
        <property name="suffix" value=".jsp"/>
      </bean>
    </beans>


    Following is my WEB-INF/applicationContext-jpa.xml 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:aop="http://www.springframework.org/schema/aop"
    		xmlns:tx="http://www.springframework.org/schema/tx"
    		xmlns:context="http://www.springframework.org/schema/context"
    		xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    				http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    				http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
    				http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-2.5.xsd ">
    
      <!-- use: ReflectiveLoadTimeWeaver for Tomcat etc -->
      <context:load-time-weaver weaver-class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
    
    
    
    
       <!-- JPA EntityManagerFactory -->
       <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
          <property name="dataSource" ref="dataSource"/>
    
    
    
          <!-- jpaVendorAdapter Hibernate, injected into emf -->
          <property name="jpaVendorAdapter">
             <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="database" value="HSQL"/>
                <property name="showSql" value="false"/>
                <!-- Data Definition Language script is generated and executed for each run -->
                <property name="generateDdl" value="false"/>
             </bean>
          </property>
       </bean>
    
        <!-- Configurer that replaces ${...} placeholders with values from a properties file -->
    	<!-- (in this case, JDBC-related settings for the dataSource definition below) -->
    	<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    		<property name="location" value="/WEB-INF/jdbc.properties"/>
    	</bean>
    
    	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName" value="${jdbc.driverClassName}"/>
    		<property name="url" value="${jdbc.url}"/>
    		<property name="username" value="${jdbc.username}"/>
    		<property name="password" value="${jdbc.password}"/>
    	</bean>
    
       <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
          <property name="entityManagerFactory" ref="entityManagerFactory"/>
          <property name="dataSource" ref="dataSource"/>
       </bean>
    
       <bean id="customerDAO" class="com.abcseo.JPACustomerDAO">
          <property name="entityManagerFactory" ref="entityManagerFactory"/>
       </bean>
    </beans>

    Following is my WEB-INF/jdbc.properties file

    Code:
    jdbc.driverClassName=org.hsqldb.jdbcDriver
    jdbc.url=jdbc:hsqldb:c:/hsqldb/data/customer
    jdbc.username=sa
    jdbc.password=
    hibernate.dialect=org.hibernate.dialect.HSQLDialect

    Following is my src/META-INF/persistence.xml file

    Code:
    <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_1_0.xsd" 
                 version="1.0">
        <persistence-unit name="dwSpring2Jpa" transaction-type="RESOURCE_LOCAL"  >
        	<non-jta-data-source>java:/DefaultDS</non-jta-data-source>
        	<properties>
        		<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
    			<property name="url" value="jdbc:hsqldb:c:/hsqldb/data/customer"/>
    			<property name="username" value="sa"/>
    			<property name="password" value=""/>
        	</properties>
        	
        </persistence-unit>
    
    </persistence>

    Now when I am trying to compile this with JBOSS 5.1 server it gives me following error

    Deployment "persistence.unit:unitName=#dwSpring2Jpa" is in error due to the following reason(s): java.lang.ClassCastException: org.hibernate.ejb.HibernatePersistence cannot be cast to javax.persistence.spi.PersistenceProvider


    Can anyone help in solving the problem?

    Thanks.

  • #2
    I have searched the net and found no solution for this. It seems JBoss 5.1 doesn't support JPA 2.0 which is implemented by Hibernate 3.5. You either use Hibernate 3.3 instead or use a different Application Server.
    JBoss 6 is an option if you don't mind using M5, but I am also looking for other AS that supports JPA 2.0, such as Geronimo and Glassfish.

    Comment

    Working...
    X