Announcement Announcement Module
Collapse
No announcement yet.
Problems with @Transactional( readonly=true ) with jpaDaoSupport Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


    • #3
      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.

      Comment


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

        Comment

        Working...
        X