java - unable to inserting new record in database using hibernate along with spring -


am inserting new record database using hibernate giving me error follows org.springframework.dao.invaliddataaccessapiusageexception: write operations not allowed in read-only mode (flushmode.manual): turn session flushmode.commit/auto or remove 'readonly' marker transaction definition.

bean.xml file

<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean class="org.springframework.jdbc.datasource.drivermanagerdatasource"     id="datasource">     <property name="driverclassname" value="com.mysql.jdbc.driver" />     <property name="url" value="jdbc:mysql://localhost:3306/test" />     <property name="username" value="root" />     <property name="password" value="root" /> </bean> <bean class="org.springframework.orm.hibernate5.localsessionfactorybean"     id="sessionfactory">     <property name="datasource" ref="datasource" />     <property name="mappingresources">         <value>student.hbm.xml</value>     </property>      <property name="hibernateproperties">         <props>             <prop key="hibernate.dialect">org.hibernate.dialect.mysql5dialect</prop>             <prop key="hibernate.show_sql">true</prop>             <prop key="hibernate.hbm2ddl.auto">update</prop>          </props>     </property> </bean> <bean class="org.springframework.orm.hibernate5.hibernatetemplate"     id="hibernatetemplate">     <property name="sessionfactory" ref="sessionfactory"></property>  </bean> <bean class="com.sj.dao.studentmasterdaoimpl" id="studentmasterdaoimpl">     <property name="hibernatetemplate" ref="hibernatetemplate"></property> </bean> 

error message

org.springframework.web.util.nestedservletexception: request processing failed; nested exception org.springframework.dao.invaliddataaccessapiusageexception: write operations not allowed in read-only mode (flushmode.manual): turn session flushmode.commit/auto or remove 'readonly' marker transaction definition. org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:982) org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:861) javax.servlet.http.httpservlet.service(httpservlet.java:622) org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:846) javax.servlet.http.httpservlet.service(httpservlet.java:729) org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:53) 

dao implementation

public class studentmasterdaoimpl implements studentmasterdao {     public studentmasterdaoimpl() {     system.out.println(getclass());     }     private hibernatetemplate hibernatetemplate;     public void sethibernatetemplate(hibernatetemplate hibernatetemplate) {     system.out.println("set hibernate template");            this.hibernatetemplate = hibernatetemplate;     }      @override     @transactional(readonly = false)     public int createstudent(student student) {         system.out.println(student);     //       hibernatetemplate.getsessionfactory().getcurrentsession().setflushmode(flushmo             de.auto);         int id = (int) hibernatetemplate.save(student);         return id;     }     @override     public list<student> getstudent(string name) {         string hql = "from student";         list list = hibernatetemplate.find(hql);         return (list<student>) list;     }       @override     public int deletestudent(int id) {         return 0;     }     @override     public student getstudent(int id) {         student student = null;         if (id > 0) {             student = (student) hibernatetemplate.get(student.class, id);          }         return student;      } } 


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -