Reputation: 10422
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>
Upvotes: 1
Views: 1392
Reputation: 10422
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;
}
});
Upvotes: 0
Reputation: 11
you can make hibernateTemplate object and override excute method
Upvotes: 1
Reputation: 26522
Most likely your operations, some of them being persiting or updating entities, on the session are not within a transactional context.
Try to enclose them within:
Session session = hibernatetemplate.getSessionFactory().openSession();
Transaction tx = session.beginTrasaction();
...
tx.commit();
session.close();
Now, when you begin the transaction, the flush mode should be implicitly set to COMMIT/AUTO.
Upvotes: 1