Search code examples
javaspringhibernatejpaspring-orm

Why i can not change flushmode in hibernate


org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.

I tried to change it in code and in xml to another flushmode but it is still Auto.

hibernatetemplate.getSessionFactory().openSession().setFlushMode(FlushMode.COMMIT);

and <prop key="org.hibernate.FlushMode">COMMIT</prop>


Solution

  • actually i solved it

    final Person object = new Person(id, name, password);
        hibernateTemplate.execute(new HibernateCallback<Person>() {
    
            public Person doInHibernate(Session session)
                    throws HibernateException {
    
                session.save(object);
                session.flush();
                return object;
            }
        });