Announcement Announcement Module
Collapse
No announcement yet.
Error creating bean with name 'entityManagerFactory' defined in ServletContext resour Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error creating bean with name 'entityManagerFactory' defined in ServletContext resour

    Hi

    I am new to spring and trying to setup spring environment
    I am getting following error
    “Error creating bean with name 'entityManagerFactory' defined in ServletContext resour”

    I am using maven + eclipse

    Error description :-
    ERROR ContextLoader:308 - Context initialization failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/datasource-config.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: No persistence units parsed from {classpath*:META-INF/persistence.xml}
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1455)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 94)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:225)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:291 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:567)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:913)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:464)
    at org.springframework.web.context.ContextLoader.conf igureAndRefreshWebApplicationContext(ContextLoader .java:385)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:284)
    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 111)
    at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:4206)
    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4705)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1057)
    at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1057)
    at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(Sta ndardService.java:525)
    at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalin a.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:414)
    Caused by: java.lang.IllegalStateException: No persistence units parsed from {classpath*:META-INF/persistence.xml}


    Attachment Attachment
    Attached Files

  • #2
    Did you happen to see this:
    Caused by: java.lang.IllegalStateException: No persistence units parsed from {classpath*:META-INF/persistence.xml}

    Seems like you might need to create the file.

    See: http://docs.jboss.org/jbossas/docs/S...h01s02s01.html

    Comment


    • #3
      I have deleted persistence.xml from /WEB-INF/classes/META_INF/ but still getting the same error
      That means control is not reaching to persistence.xml

      Any idea on problem

      Comment


      • #4
        META-INF needs to be on the root of the classpath (eg. /src/main/resources)

        Comment


        • #5
          Originally posted by bsanders1979 View Post
          META-INF needs to be on the root of the classpath (eg. /src/main/resources)
          i was saying about deployment path respective to tomcat ..
          and i have noticed error in webflow-config.xml file in beans graph but unable to figure out root cause
          see the error in attachment
          Attachment
          Attached Files

          Comment


          • #6
            I figured that I would say you had the file in the right place after all.

            Here's how you might try defining your beans...
            Code:
                <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                    <property name="jpaVendorAdapter">
                        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
                    </property>
                </bean>
                <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
                    <property name="entityManagerFactory" ref="entityManagerFactory" />
                </bean>
            And here's how you might define persistence.xml (you don't have to put the config in hibernate.cfg.xml)
            Code:
            <?xml version="1.0" encoding="UTF-8"?>
            <persistence version="1.0"
            	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"
            >
            	
                <persistence-unit name="XE">
                    <properties>
                        <property name="hibernate.ejb.cfgfile" value="hibernate.cfg.xml"/>
                    </properties>
                </persistence-unit>
            	
            </persistence>
            Last edited by bsanders1979; Jul 12th, 2013, 08:44 PM. Reason: Added persistence.xml

            Comment


            • #7
              Originally posted by bsanders1979 View Post
              I figured that I would say you had the file in the right place after all.

              Here's how you might try defining your beans...
              Code:
                  <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                      <property name="jpaVendorAdapter">
                          <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
                      </property>
                  </bean>
                  <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
                      <property name="entityManagerFactory" ref="entityManagerFactory" />
                  </bean>
              And here's how you might define persistence.xml (you don't have to put the config in hibernate.cfg.xml)
              Code:
              <?xml version="1.0" encoding="UTF-8"?>
              <persistence version="1.0"
              	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"
              >
              	
                  <persistence-unit name="XE">
                      <properties>
                          <property name="hibernate.ejb.cfgfile" value="hibernate.cfg.xml"/>
                      </properties>
                  </persistence-unit>
              	
              </persistence>
              here is my persistence.xml
              Code:
              <?xml version="1.0" encoding="UTF-8"?>
              <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="default" transaction-type="RESOURCE_LOCAL">
                            
                            <provider>org.hibernate.ejb.HibernatePersistence</provider>  
                      </persistence-unit>
              </persistence>

              Comment


              • #8
                I looked at a Roo project which seems to better resemble your setup.
                You might try adding this to your entityManagerFactory
                Code:
                        <property name="persistenceUnitName" value="default"/>
                The trx manager does not hold a direct reference to the DS, but I couldn't say if that will cause problems or not.

                Comment

                Working...
                X