Announcement Announcement Module
Collapse
No announcement yet.
Project Deployment on WebSphere Fails (entityManagerFactory error) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Project Deployment on WebSphere Fails (entityManagerFactory error)

    Hello

    I am struggling for four days to deploy my application on a WebSphere 7 server. Deploying on a Glassfish V3.1 does not invoke any problems. Next error is very common and various threads cover this topics on the forum. But no single thread released me from hell.

    Error
    Code:
    Error creating bean with name 'entityManagerFactory' defined in class pa
    th resource [config/persistence-ctx.xml]: Invocation of init method failed;
    Information
    Spring version : Spring 3.0.2 Final
    Hibernate version : 3.5.1 Final
    JPA 2.0 Implementation : Hibernate
    Deployment file type: WAR
    Maven build method : mvn clean install
    We use AspectJ

    Server
    Class loader policy : PARENT_LAST
    Server Version : 7.0.0.7


    Notes
    - I run IntelliJ 10 and dubbel checked if all dependencies have scope "compile" (if not solely test related) in the project structure.
    - I Cannot find any secondary JPA 2.0 implementation in my Web-Inf/Lib which might raise a conflict (located on the WebSphere server)

    Stack Trace :

    Code:
    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: mypackage.ProcessLogDao mypackage.ProcessOverviewController.processLogDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean wit
    h name 'processLogDaoImpl': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name 'entityManagerFactory' defined in class path resource [config/dh-persistence-ctx.xml]: Invocation of init method failed; nested excep
    tion is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode;
     
    <!-- Some repeating stack trace omitted -->
    
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [conf
    ig/persistence-ctx.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getS
    haredCacheMode()Ljavax/persistence/SharedCacheMode;
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1412)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
            at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findDefaultEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.
    java:529)
            at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:49
    5)
            at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostPr
    ocessor.java:656)
            at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostPro
    cessor.java:629)
            at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147)
            at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
            at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:3
    38)
            ... 51 more
    Caused by: java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode;
            at org.hibernate.ejb.util.LogHelper.logPersistenceUnitInfo(LogHelper.java:39)
            at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:509)
    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:72)
            at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:22
    5)
            at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1469)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1409)
            ... 64 more
    Persistence.xml
    Code:
        <persistence-unit name="default">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <class>mypackage.ProcessLog</class>
            <class>mypackage.ProcessLogDetail</class>
        </persistence-unit>
    Persistence-ctx.cml
    Code:
        <bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
            <property name="persistenceXmlLocations">
                <list>
                    <value>classpath*:/config/persistence.xml</value>
                </list>
            </property>
            <property name="defaultDataSource" ref="dataSource"/>
            <property name="persistenceUnitPostProcessors">
                <list>
                    <bean class="mypackage.orm.jpa.MergingPersistenceUnitPostProcessor"/>
                </list>
            </property>
        </bean>
    
        <bean id="dataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
            <property name="targetDataSource" ref="mainDataSource"/>
        </bean>
    
        <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <property name="jpaVendorAdapter">
                <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                    <property name="database" value="${jpa.database}"/>
                </bean>
            </property>
            <property name="persistenceUnitName" value="default"/>
            <property name="persistenceUnitManager" ref="persistenceUnitManager"/>
            <property name="dataSource" ref="dataSource"/>
        </bean>
    
        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
            <property name="entityManagerFactory" ref="entityManagerFactory"/>
        </bean>
    Own notes
    - I really do not understand why I can deploy on a Glassfish Server (on my local machine) but not on Websphere 7. I do NOT have the feature pack "WebSphere Application Server V7 Feature Pack for OSGi Applications and Java Persistence API 2.0" installed (is this really mandotory ? Because what I conclude it only expands OpenJPA support and not a third-party provider like hibernate)
    - I went trough various topics on this site and JBoss but none of the solution helped me
    - Full list of my classpath jars can be requested if necessary
    Last edited by Den Ian; May 23rd, 2011, 10:36 AM.

  • #2
    I've never used the WebSphere server and can't help much in that area, but I could see that you are using a custom PersistenceUnitPostProcessors implementation.
    And to isolate the problem - I don't know if it is one - you could try the DefaultPersistenceUnitManager with default values, mainly this one:
    <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml"/>
    Regards,

    Comment


    • #3
      Well I applied your tip, but it did not changed anything to the outcome Thanks anyway for your effort

      Comment


      • #4
        The error is:
        Code:
        nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getS
        haredCacheMode()Ljavax/persistence/SharedCacheMode;
        Means that the classloader use a JPA 1 jar (persistence.jar or something like that). The jar come from websphere i guess.

        Either you can replace this jar inside websphere or you can change the classloader order to use the persistance jar from your application.

        Comment


        • #5
          My Classloader order does PARENT_LAST, should that not load the applicable jar from my classpath ?

          Comment


          • #6
            I've never use websphere but in weblogic sometime ask the classloader to load application class first is not enough...

            Comment


            • #7
              Ok people, I solved the problem.

              Websphere has also a classloader policy that can be configured on module level, this had the PARENT_FIRST policy active. After changing this setting also to PARENT_LAST also I was able to load all the jars from my WEB-INF/lib.

              Usefull link : http://josephamrithraj.wordpress.com...-in-websphere/

              Know I only have a "Error 500: javax.servlet.UnavailableException: SRVE0201E: Servlet [org.springframework.web.servlet.DispatcherServlet]: not a servlet class".
              If you find a solution I will add this solution also.

              thanks

              Comment


              • #8
                Solved by renaming persistence.xml to something else and reference it accord.

                Hi,

                we solved the entityManagerFactory error by renaming the persistence.xml to e.g. jpa-persistence.xml and reference it in the spring application-config.xml as e.g. <property name="persistenceXmlLocation" value="classpath:META-INF/jpa-persistence.xml" />

                Background:
                WebSphere container has a built-in scan mechanism which looks after existing of any persistence.xml in any application. Knowing that, solution was simple s.a. + having your own jpa 2.0 jar + classloder mode parent_last within your application.

                Hope that helps,
                Jan

                Comment

                Working...
                X