Announcement Announcement Module
Collapse
No announcement yet.
transaction and readonly Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • transaction and readonly

    Hello,

    I define a transaction manager with org.springframework.orm.jpa.JpaTransactionManager .

    We use Hibernate and postgreSQL.

    We define a method with
    @Transactional(value="transationManager", readOnly=true)
    We do into this method only a select. when we watch the log of BDD we see that the transaction terminates with a commit.

    It's only a select request. But is it normal that the transaction finished with a commit and not a rollback?

    Thanks for you response.

  • #2
    please need help

    I try a test

    Code:
    public class MyClassA{
    
     @PersistenceContext(unitName = "persistenceUnitMarcoPoloCms")
     private EntityManager entityManager;
    
     public MyEntity save(MyEntity entity){
        final MyEntity savedEntity = this.entityManager.merge(entity);
        this.entityManager.flush();
        return savedEntity;
     }
    
     @Transactional(value="transationManager", readOnly=true) 
     public List<MyEntity> getMyEntity(Integer id){
       String myrequest = "select ...";
       TypedQuery<MyEntity> typedQuery = this.entityManager.createQuery(myrequest, MyEntity.class);
       typedQuery.setParameter(1, id);
       List<MyEntity> myList = typedQuery.getResultList();
       if (CollectionUtils.isNotEmpty(myList)) {
    	myList.get(0).setName(myList.get(0).getName() + " testName");
    	save(myList.get(0));
       }
       return myList;
     }
    }
    in my spring context i define:
    Code:
      ...
      <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
    		p:entityManagerFactory-ref="entityManagerFactory"/>
      ...

    I can save modification. I don't know why i can save modification in a transaction readonly.
    Please need help.

    Comment

    Working...
    X