We are upgrading our project from Hibernate 3.6.10 to Hibernate 5.2.0 but getting errors while migrating. I have gone through many posts here on StackOverFlow and Google but did not found any solution.
Consider the code reference this website. I only made the database connections are to PostgreSQL database.
If I run this sample after adding these JARs (ALL Added JAR files screenshot) except the hibernate JAR is 3.6.10-final, It works totally fine. But if I make these changes for hibernate 5 upgrade:
- Changing JAR file added as Hibernate-core-5.2.1-Final.jar
- Changing reference of hibernate3 files to hibernate5(3 replacements; 1 in EmployeeDao import and another 2 in applicationContext.xml)
It throws the following error:
Exception in thread "main" 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.
at org.springframework.orm.hibernate5.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1132)
at org.springframework.orm.hibernate5.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:618)
at org.springframework.orm.hibernate5.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:615)
at org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:340)
at org.springframework.orm.hibernate5.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:307)
at org.springframework.orm.hibernate5.HibernateTemplate.save(HibernateTemplate.java:615)
at hibernate.test.EmployeeDao.saveEmployee(EmployeeDao.java:12)
at hibernate.test.InsertTest.main(InsertTest.java:21)
And I made these changes as well but got the same error: 1. Commenting this in EmployeeDao:
/*HibernateTemplate template;
public void setTemplate(HibernateTemplate template) {
this.template = template;
} */
and extending HibernateDaoSupport, so that it gives sessionFactory setter.
And replacing below code to:
public void saveEmployee(Employee e){
template.save(e);
}
this:
public void saveEmployee(Employee e){
this.getHibernateTemplate().save(e);
}
After debugging I came to know that in HibernateTemplate class provided by Spring-orm-4.3.1 Jar is throwing the mentioned error.
Can anyone help me out with this :O. We have stuck here for ages. I appreciate help.