Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: JPA problem, entityManagerCreation

  1. #11
    Join Date
    Mar 2006
    Location
    A place to call home
    Posts
    76

    Default

    Quote 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 at 05:14 AM.

  2. #12
    Join Date
    May 2006
    Location
    London, UK
    Posts
    22

    Default

    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

  3. #13
    Join Date
    Mar 2006
    Location
    A place to call home
    Posts
    76

    Default

    Quote 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>
    Quote 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.

  4. #14
    Join Date
    May 2006
    Location
    London, UK
    Posts
    22

    Default

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

  5. #15
    Join Date
    May 2006
    Location
    London, UK
    Posts
    22

    Default

    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

  6. #16
    Join Date
    Mar 2006
    Location
    A place to call home
    Posts
    76

    Thumbs up

    Quote Originally Posted by Micke
    Could you please post your application context and persistence xml files.
    No problems.

    persistence.xml
    Code:
    <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
    
       <persistence-unit name="SpringJpaGettingStarted" transaction-type="RESOURCE_LOCAL" />
    
    </persistence>
    toplinkApplicationContext.xml
    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="blog.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.HSQLPlatform" />
             </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="org.hsqldb.jdbcDriver" />
          <!--<property name="url" value="jdbc:hsqldb:hsql://localhost/" />-->
          <property name="url" value="jdbc:hsqldb:hsql://localhost:1717/springJPA" />
          <property name="username" value="sa" />
          <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>
    HTH, Peter

  7. #17

    Default

    It's interesting how people prefer immutable objects but most people I know use setter based injection.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •