Announcement Announcement Module
Collapse
No announcement yet.
jpa-entitymanagerfactory-datasource config Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • jpa-entitymanagerfactory-datasource config

    Hi,
    I have an issue setting up datasource for my entity manager factory under spring.

    spring config xml
    =========================
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="com.mysql.jdbc.Driver" />
    <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/nbl" />
    <property name="user" value="********" />
    <property name="password" value="*******" />
    <property name="maxPoolSize" value="10" />
    <property name="maxStatements" value="0" />
    <property name="minPoolSize" value="5" />
    </bean>
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityMana gerFactoryBean">

    <property name="persistenceUnitName" value="NBL" />
    <property name="dataSource" ref="dataSource" />
    <property name="jpaVendorAdapter">
    <bean
    class="org.springframework.orm.jpa.vendor.Hibernat eJpaVendorAdapter">
    <property name="showSql" value="false" />
    <property name="generateDdl" value="true" />
    <property name="database" value="MYSQL" />
    </bean>
    </property>
    </bean>

    Exception
    ===========================================
    i am seeing this error:

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in class path resource
    [com/pjs2k/nbl/test/resource/spring-config-test.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException:
    Failed to convert property value of type [com.mchange.v2.c3p0.ComboPooledDataSource] to required type [javax.sql.DataSource] for property 'dataSource';
    nested exception is java.lang.IllegalArgumentException: Original must not be null
    ...
    Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [com.mchange.v2.c3p0.ComboPooledDataSource]
    to required type [javax.sql.DataSource] for property 'dataSource'; nested exception is java.lang.IllegalArgumentException: Original must not be null
    at org.springframework.beans.BeanWrapperImpl.convertF
    orProperty(BeanWrapperImpl.java:391)

    Is this some bean set operation problem.

    Not sure what i ma doing wrong. Have configured my setup based on samples from the internet.

    Am running eclipse with jdk1.5

    Any pointers much appeciated.

    Thanks in advance

  • #2
    LocalEntityManager

    I see this does not have a datasource property.
    What is the correct way to set up the datasource with LocalEntityManagerFactory?

    Comment


    • #3
      Feel free to use the forum search

      Comment


      • #4
        Search

        Hi dennis,
        I have already searched the forum and indeed been googling. I havent just posted without searching/looking myself.
        Maybe i am not searching correctly but this config doesnt seem obvious to me and i have wasted much time already trying to set this up.
        Any pointers would much appreciated-

        Should the datasource get setup in Persistence.xml

        best regards

        Comment


        • #5
          You can skip the JpaVendorAdapter and Datasource, and provide the settings in persistence.xml, but the following is a working example of specifying it in the application context:

          Code:
          	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
          		<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
          		<property name="url" value="jdbc:hsqldb:mem:test" />
          		<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>
          	<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
          		<property name="databasePlatform" value="org.hibernate.dialect.HSQLDialect" />
          		<property name="showSql" value="true" />
          		<property name="generateDdl" value="true" />
          	</bean>
          	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
          		<property name="persistenceUnitName" value="hibernate-test-unit" />
          		<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
          		<property name="dataSource" ref="dataSource" />
          	</bean>
          Cheers

          G

          Comment


          • #6
            thanks

            Thanks G,

            I did manage to get sorted in the end by (re-reading the documentation more thoroughly) using the LocalContainerEntityManagerFactory and configuring the datasource.

            Thanks for taking the time to respond.

            p

            Comment

            Working...
            X