JPA Change default Flushmode from AUTO to COMMIT

后端 未结 2 693
青春惊慌失措
青春惊慌失措 2021-01-02 07:24

I\'ve tried several ways to change the FlushMode to the complete application. Is this right or is there another way to do it?

I don\'t want to do this pragmmatically

2条回答
  •  心在旅途
    2021-01-02 07:56

    Try this

    
    

    Testing this on a standalone program I can see the changed value of underlying Hibernate Session / EntityManager from AUTO to COMMIT

    Here is my persistence.xml

    
    
      
      org.hibernate.jpa.HibernatePersistenceProvider  
    
      com.test.TestEntity  
      ENABLE_SELECTIVE 
       
          
          
          
          
          
               
           
          
          
          
                
           
           
          
          
          
          
          
          
          
            
      
    
    

    And here is how I test it

     EntityManagerFactory emf  = Persistence.createEntityManagerFactory("JPATest");
     EntityManager em = emf.createEntityManager();
     Session session = em.unwrap(Session.class);
     System.out.println("Underlying Hibernate session flushmode #######         "+session.getFlushMode());
     System.out.println("EntityManager flushmode                #######         "+em.getFlushMode());
    

    This gives me

    Underlying Hibernate session flushmode #######         COMMIT
    EntityManager flushmode                #######         COMMIT
    

    If I omit the property in presistence.xml, I get this

    Underlying Hibernate session flushmode #######         AUTO
    EntityManager flushmode                #######         AUTO
    

提交回复
热议问题