Results 1 to 4 of 4

Thread: Problems with @Transactional( readonly=true ) with jpaDaoSupport

  1. #1
    Join Date
    Oct 2005
    Location
    Bergen, Norway
    Posts
    128

    Default Problems with @Transactional( readonly=true ) with jpaDaoSupport

    Hi!

    I've got a simple dao which extends JpaDaoSupport (using openJpa).
    All is swell and it works - it only does a select - no updates.

    I then added @Transactional( readOnly=true ) to the dao-impl,
    and setup a transaction manager:


    <code>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionM anager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    and <tx:annotation-driven />

    </code>

    The same select now executes an update!:

    <code>
    2007-11-30 12:15:11,449 [main] DEBUG org.springframework.transaction.support.Transactio nSynchronizationManager - Retrieved value [org.springframework.orm.jpa.EntityManagerHolder@13 eae6e] for key [org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean@14382c6] bound to thread [main] (TransactionSynchronizationManager.java:140)
    15618 CustomerProgramme TRACE [main] openjpa.jdbc.SQL - <t 15079989, conn 20704708> executing prepstmnt 8611945 SELECT .....
    15665 CustomerProgramme TRACE [main] openjpa.jdbc.SQL - <t 15079989, conn 20704708> [47 ms] spent
    2007-11-30 12:15:11,605 [main] DEBUG org.springframework.transaction.interceptor.Transa ctionInterceptor - Completing transaction for [no.dnb.ee.tep.server.func.personkunde.CustomerProg rammeDAO.getCustomerById] (TransactionAspectSupport.java:317)
    2007-11-30 12:15:11,605 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Triggering beforeCommit synchronization (AbstractPlatformTransactionManager.java:833)
    2007-11-30 12:15:11,605 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Triggering beforeCompletion synchronization (AbstractPlatformTransactionManager.java:846)
    2007-11-30 12:15:11,605 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Initiating transaction commit (AbstractPlatformTransactionManager.java:660)
    2007-11-30 12:15:11,605 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Committing JPA transaction on EntityManager [org.apache.openjpa.persistence.EntityManagerImpl@6 88e91] (JpaTransactionManager.java:433)
    15712 CustomerProgramme TRACE [main] openjpa.jdbc.SQL - <t 15079989, conn 20704708> executing prepstmnt 4537415 UPDATE ......
    15759 CustomerProgramme TRACE [main] openjpa.jdbc.SQL - <t 15079989, conn 20704708> [47 ms] spent


    </code>

    which seems realy odd - any pointers?

  2. #2
    Join Date
    Sep 2004
    Posts
    1,086

    Default

    You dont have to execute explicit updates to persiste changes to JPA entities, EntityManager will pick up all dirty objects at the end of the transaction and update them automatically.

  3. #3
    Join Date
    Oct 2005
    Location
    Bergen, Norway
    Posts
    128

    Default

    Quote Originally Posted by dejanp View Post
    You dont have to execute explicit updates to persiste changes to JPA entities, EntityManager will pick up all dirty objects at the end of the transaction and update them automatically.
    But it's weird that this only happens when annotating the Dao with @Transactional.

  4. #4
    Join Date
    Sep 2004
    Posts
    1,086

    Default

    Well, not really. If there is no transaction objects are never flushed.

Posting Permissions

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