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

Thread: JPA and Spring

  1. #11
    Join Date
    May 2007
    Posts
    16

    Default

    sure, thanx dude.give me the dao and app-context file.

  2. #12
    Join Date
    Sep 2007
    Location
    Cluj Napoca, Romania
    Posts
    9

    Thumbs up

    Hi. here's the important part from the app context xml:
    <code>

    <tx:annotation-driven />
    <bean id="persistenceUnitManager"
    class="org.springframework.orm.jpa.persistenceunit .DefaultPersistenceUnitManager">
    <property name="persistenceXmlLocations">
    <list>
    <value>classpathersistence.xml</value>
    </list>
    </property>
    </bean>
    <bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
    <property name="persistenceUnitManager"
    ref="persistenceUnitManager" />
    <property name="persistenceUnitName"
    value="persistence-unit-name" />
    </bean>
    <bean id="transactionManager"
    class="org.springframework.orm.jpa.JpaTransactionM anager">
    <property name="entityManagerFactory"
    ref="entityManagerFactory" />
    </bean>
    <bean
    class="org.springframework.orm.jpa.support.Persist enceAnnotationBeanPostProcessor" />

    </code>

    And the DAO is an ordinary class. The only thing is that it has @Transactional

    Hope it helps.

  3. #13
    Join Date
    Sep 2007
    Location
    Cluj Napoca, Romania
    Posts
    9

    Default

    Very important!!! Make sure you put <tx:annotation-driven/> in your xml file! Otherwise, the @Transactional will be in vain.

  4. #14
    Join Date
    Nov 2007
    Posts
    177

    Default Any solution to the above problem

    I have the very same problem...

  5. #15

    Default Use Annotation Driven Transaction Manager

    Try using the following approach...
    <bean
    class="org.springframework.orm.jpa.support.Persist enceAnnotationBeanPostProcessor" />

    <bean id="catalogService"
    class="com.mobchannel.store.catalog.service.Catalo gServiceImpl"
    scope="singleton" />

    <bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName">
    <value>com.mysql.jdbc.Driver</value>
    </property>
    <property name="url">
    <value>${mobchannel.database.uri}</value>
    </property>
    <property name="username">
    <value>${mobchannel.database.user.username}</value>
    </property>
    <!-- Make sure <value> tags are on same line - if they're not,
    authentication will fail -->
    <property name="password">
    <value>${mobchannel.database.user.password}</value>
    </property>
    </bean>
    <bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="jpaVendorAdapter">
    <bean
    class="org.springframework.orm.jpa.vendor.Hibernat eJpaVendorAdapter">
    <property name="database" value="MYSQL" />
    <property name="showSql">
    <value>${mobchannel.hibernate.showsql}</value>
    </property>
    </bean>
    </property>
    </bean>
    <bean id="transactionManager"
    class="org.springframework.orm.jpa.JpaTransactionM anager">
    <property name="entityManagerFactory"
    ref="entityManagerFactory" />
    </bean>
    <tx:annotation-driven transaction-manager="transactionManager" />

Posting Permissions

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