Announcement Announcement Module
Collapse
No announcement yet.
JPA problem, entityManagerCreation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JPA problem, entityManagerCreation

    Hi,
    I'm new to Spring and even newer to JPA.

    When trying to follow this tutorial
    http://blog.springframework.com/mark...-in-spring-20/
    I get the following exception :

    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restaurantDao' defined in class path resource [demo/jpa/dao/applicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [demo/jpa/dao/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: demo/applets/SpreadSheet/SpreadSheet (wrong name: SpreadSheet)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [demo/jpa/dao/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: demo/applets/SpreadSheet/SpreadSheet (wrong name: SpreadSheet)
    Caused by: java.lang.NoClassDefFoundError: demo/applets/SpreadSheet/SpreadSheet (wrong name: SpreadSheet)
    	at java.lang.ClassLoader.defineClass1(Native Method)
    	at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    	at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    	at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    	at org.springframework.instrument.classloading.AbstractOverridingClassLoader.loadClass(AbstractOverridingClassLoader.java:93)
    	at oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.isClassPersistent(PersistenceUnitProcessor.java:591)
    	at oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.getPersistentClassNamesFromDirectory(PersistenceUnitProcessor.java:539)
    	at oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.getPersistentClassNamesFromURL(PersistenceUnitProcessor.java:558)
    	at oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.buildPersistentClassSet(PersistenceUnitProcessor.java:401)
    	at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.buildEntityList(EntityManagerSetupImpl.java:159)
    	at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:492)
    	at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createContainerEntityManagerFactory(EntityManagerFactoryProvider.java:154)
    	at org.springframework.orm.jpa.ContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(ContainerEntityManagerFactoryBean.java:181)
    	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:232)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:901)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:870)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:393)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:256)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:167)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:219)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:115)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:798)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:589)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:389)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:256)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:167)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:253)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:332)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at org.springframework.test.jpa.AbstractJpaTests.runBare(AbstractJpaTests.java:180)
    	at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:32)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
    Why is it trying to load the emo/applets/SpreadSheet/SpreadSheet class??

    This is my application context, the same as the tutorial except for me using MySQL :

    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="restaurantDao" class="demo.jpa.dao.JpaRestaurantDao">
    		<property name="entityManagerFactory" ref="entityManagerFactory"/>
    	</bean>
    
    	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.ContainerEntityManagerFactoryBean">
    		<property name="dataSource" ref="dataSource"/>
    		<property name="jpaVendorAdapter">
    			<bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter">
    				<property name="showSql" value="true"/>
    				<property name="generateDdl" value="true"/>
    				<property name="databasePlatform" value="oracle.toplink.essentials.platform.database.MySQL4Platform"/>
    			</bean>
    		</property>
    		<property name="loadTimeWeaver">
    			<bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver"/>
    		</property>
    	</bean>
    
    	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    		<property name="url" value="jdbc:mysql://mysql-mikael.ebi.ac.uk:4033/jpatest"/>
    		<property name="username" value=""/>
    		<property name="password" value=""/>
    	</bean>
    
    	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory"/>
    		<property name="dataSource" ref="dataSource"/>
    	</bean>
    </beans>
    Greateful for any help and/or pointers to Spring-JPA beginner resources

    Thanks
    Micke

  • #2
    Micke, what does your persistence.xml look like? Can you post that too?

    S.

    Comment


    • #3
      Hi

      Here it is:

      Code:
      <?xml version="1.0"?>
      <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
      	<persistence-unit name="SpringJpaGettingStarted" transaction-type="RESOURCE_LOCAL"/>
      </persistence>

      Comment


      • #4
        Hm. Not much exciting in there :-)

        Why does it complain about the name of 'demo/applets/SpreadSheet/SpreadSheet'? See the double SpreadSheet. Do you have a capitalized package name or so? Maybe TopLink gets confused by that?

        S.

        Comment


        • #5
          I don't have the package demo/applets in my project at all, googled it and seems like there is a Swing demo with that class

          The only thing is that my base package is demo (demo.jpa), but I don't see how that can create the observed problem.
          No capitalized package names either.

          If you can't see anything wrong, I'll try a bit of IDE refactoring tomorrow and rename the base package.

          Thanks
          - Micke

          Comment


          • #6
            Just renamed the base package to test, but still get the same weird exception

            Comment


            • #7
              Originally posted by Micke
              Just renamed the base package to test, but still get the same weird exception
              Key to this is probably that SpreadSheet class on your classpath. Maybe some leftover from a previous project?

              S.

              Comment


              • #8
                Originally posted by Stefan Arentz
                Key to this is probably that SpreadSheet class on your classpath. Maybe some leftover from a previous project?

                S.
                The class comes from the 1.5 jdk, which is put on the path by intellij, not sure what this has to do with creation of the entityManagerFactory though??

                When switching from ContainerEntityManagerFactoryBean to the Local......FactoryBean , the error disapears (but is replaced by some other since I don't know what this actually does or how to set that up ).

                Comment


                • #9
                  Originally posted by Micke
                  The class comes from the 1.5 jdk, which is put on the path by intellij, not sure what this has to do with creation of the entityManagerFactory though??

                  When switching from ContainerEntityManagerFactoryBean to the Local......FactoryBean , the error disapears (but is replaced by some other since I don't know what this actually does or how to set that up ).
                  I've tried the same tutorial with IntelliJ (Demetra build 5321), HSQLDB 1.8.0.4 and Java 1.5.0_07 and everything works just fine.

                  When I switched from Toplink to Hibernate, two of the test cases failed though. It seems like Hibernate is returning more entites than Toplink for some of the queries...

                  Cheers

                  Comment


                  • #10
                    Ok, I'll give hibernate a go.

                    Thanks

                    Comment


                    • #11
                      Originally posted by Micke
                      Ok, I'll give hibernate a go.

                      Thanks
                      Just to clarify myself:
                      First, I got it working with Toplink. Then I switched to Hibernate just for kicks...

                      One thing to notice is that this tutorial is working with Glassfish persistence v2-b02(as the blogger used) and v2-b06 but not with the latest build which is v2-b07.
                      Last edited by Wesslan; Jun 16th, 2006, 05:14 AM.

                      Comment


                      • #12
                        Hi,
                        which is the databasePlatform to use with HSQLDB using hibernate?

                        Another question

                        I have another test project testing JPA without Spring and in that I specify all the connection details in the persistence.xml file:

                        Code:
                        	   <properties>
                                 <property name="hibernate.connection.driver_class"
                                    value="org.hsqldb.jdbcDriver"/>
                                 <property name="hibernate.connection.username"
                                    value="sa"/>
                                 <property name="hibernate.connection.password"
                                    value=""/>
                                 <property name="hibernate.connection.url"
                                    value="jdbc:hsqldb:hsql://localhost"/>
                                 <property name="hibernate.dialect"
                                    value="org.hibernate.dialect.HSQLDialect"/>
                                 <property name="hibernate.hbm2ddl.auto"
                                    value="update"/>
                              </properties>
                        Which is the preffered way of setting up the connection details, in Spring on in persistence.xml ? Or don't I have a choice using Spring?

                        Cheers

                        Comment


                        • #13
                          Originally posted by Micke
                          Hi,
                          which is the databasePlatform to use with HSQLDB using hibernate?
                          For Hibernate I use:
                          Code:
                                <property name="jpaVendorAdapter">
                                   <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                                      <property name="database" value="HSQL" />
                                      <property name="showSql" value="true" />
                                      <property name="generateDdl" value="true" />
                                   </bean>
                                </property>
                          Originally posted by Micke
                          I have another test project testing JPA without Spring and in that I specify all the connection details in the persistence.xml file.
                          Which is the preffered way of setting up the connection details, in Spring on in persistence.xml ? Or don't I have a choice using Spring?

                          Cheers
                          I'm quite new to this also so I don't know what the preffered "Spring way" is but you certainly have the choice of specifying your connection details in persistence.xml if you like.
                          I like to keep my persistence.xml as small as possible and put the configuration into Spring.

                          Comment


                          • #14
                            Thanks for the help, will try this now. Fingers crossed

                            Comment


                            • #15
                              Hi again.

                              Could you please post your application context and persistence xml files.

                              I get this error now, think it has something to do with trying to look up the XSD for the persistence.xml file..

                              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="SpringJpaGettingStarted" transaction-type="RESOURCE_LOCAL"/>
                              </persistence>
                              The excpetion I get :
                              Code:
                              org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restaurantDao' defined in class path resource [test/jpa/dao/applicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [test/jpa/dao/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Cannot parse persistence unit from class path resource [META-INF/persistence.xml]
                              Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [test/jpa/dao/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Cannot parse persistence unit from class path resource [META-INF/persistence.xml]
                              Caused by: java.lang.IllegalArgumentException: Cannot parse persistence unit from class path resource [META-INF/persistence.xml]
                              	at org.springframework.orm.jpa.PersistenceUnitReader.readPersistenceUnitInfos(PersistenceUnitReader.java:117)
                              	at org.springframework.orm.jpa.ContainerEntityManagerFactoryBean.parsePersistenceUnitInfo(ContainerEntityManagerFactoryBean.java:223)
                              	at org.springframework.orm.jpa.ContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(ContainerEntityManagerFactoryBean.java:141)
                              	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:232)
                              	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:901)
                              	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:870)
                              	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:393)
                              	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:256)
                              	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:167)
                              	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:219)
                              	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:115)
                              	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:798)
                              	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:589)
                              	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:389)
                              	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:256)
                              	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:167)
                              	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:253)
                              	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:332)
                              	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                              	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                              	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                              	at org.springframework.test.jpa.AbstractJpaTests.runBare(AbstractJpaTests.java:180)
                              	at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:32)
                              	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                              	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                              	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                              	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
                              Caused by: java.io.FileNotFoundException: class path resource [persistence_1_0.xsd] cannot be resolved to URL because it does not exist
                              	at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:157)
                              	at org.springframework.orm.jpa.PersistenceUnitReader.validateResource(PersistenceUnitReader.java:281)
                              	at org.springframework.orm.jpa.PersistenceUnitReader.readPersistenceUnitInfos(PersistenceUnitReader.java:108)
                              	... 39 more

                              Comment

                              Working...
                              X