hibernate3 - org.hibernate.exception.SQLGrammarException: could not insert i am geting -
hi trying insert new row in table using hibernate bean class getting exception
org.hibernate.exception.sqlgrammarexception: not insert
i using below mentioned code:
public class calendar implements serializable { private static final long serialversionuid = 1l; private integer id; private date day; private string festival; private boolean c; /*setterd getters*/ }
hbm file:
?xml version="1.0"?> <!doctype hibernate-mapping public "-//hibernate/hibernate mapping dtd 3.0//en" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="com.calendar" table="t_calendar"> <id name="id" type="java.lang.integer"> <column name="id" /> <generator class="identity" /> </id> <property name="day" type="date"> <column name="day" not-null="true" /> </property> <property name="festival" type="string"> <column name="festival" /> </class> </hibernate-mapping>
action class:
irholidaycalendar holidaylist = new irholidaycalendar(); holiday.setfestival(festival); holiday.setday(date1); holiday.setc(c_0001); calendar obj = caldao.saveobject(holiday);
dao class
public calendar savecalender(calendar obj) { session session = gethibernatetemplate().getsessionfactory().opensession(); transaction tx = session.begintransaction(); irholidaycalendar holiday = null; try { holiday = (calendar) session.merge(obj); tx.commit(); } catch (hibernateexception e) { log.error("not able update", e); tx.rollback(); } { session.close(); } return holiday; }
execption
org.hibernate.exception.sqlgrammarexception: not insert: [com.calendar] @ org.hibernate.exception.sqlstateconverter.convert(sqlstateconverter.java:92) @ org.hibernate.exception.jdbcexceptionhelper.convert(jdbcexceptionhelper.java:66) @ org.hibernate.id.insert.abstractreturningdelegate.performinsert(abstractreturningdelegate.java:64) @ org.hibernate.persister.entity.abstractentitypersister.insert(abstractentitypersister.java:2329) @ org.hibernate.persister.entity.abstractentitypersister.insert(abstractentitypersister.java:2836) @ org.hibernate.action.entityidentityinsertaction.execute(entityidentityinsertaction.java:71) @ org.hibernate.engine.actionqueue.execute(actionqueue.java:268) @ org.hibernate.engine.actionqueue.executeactions(actionqueue.java:260) @ org.hibernate.engine.actionqueue.executeactions(actionqueue.java:179) @ org.hibernate.event.def.abstractflushingeventlistener.performexecutions(abstractflushingeventlistener.java:321) @ org.hibernate.event.def.defaultflusheventlistener.onflush(defaultflusheventlistener.java:51) @ org.hibernate.impl.sessionimpl.flush(sessionimpl.java:1206) @ org.springframework.orm.hibernate3.hibernateaccessor.flushifnecessary(hibernateaccessor.java:392) @ org.springframework.orm.hibernate3.hibernatetemplate.doexecute(hibernatetemplate.java:412) @ org.springframework.orm.hibernate3.hibernatetemplate.executewithnativesession(hibernatetemplate.java:379) @ org.springframework.orm.hibernate3.hibernatetemplate.merge(hibernatetemplate.java:858) @ com.inrev.workflow.dao.impl.irworkflowtatdaoimpl.saveobject(irworkflowtatdaoimpl.java:533) @ com.inrev.workflow.action.irholidaycalendaraction.addlist(irholidaycalendaraction.java:396) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ ognl.ognlruntime.invokemethod(ognlruntime.java:870) @ ognl.ognlruntime.callappropriatemethod(ognlruntime.java:1293) @ ognl.objectmethodaccessor.callmethod(objectmethodaccessor.java:68) @ com.opensymphony.xwork2.ognl.accessor.xworkmethodaccessor.callmethodwithdebuginfo(xworkmethodaccessor.java:117) @ com.opensymphony.xwork2.ognl.accessor.xworkmethodaccessor.callmethod(xworkmethodaccessor.java:108) @ ognl.ognlruntime.callmethod(ognlruntime.java:1369) @ ognl.astmethod.getvaluebody(astmethod.java:90) @ ognl.simplenode.evaluategetvaluebody(simplenode.java:212) @ ognl.simplenode.getvalue(simplenode.java:258) @ ognl.ognl.getvalue(ognl.java:494) @ ognl.ognl.getvalue(ognl.java:458) @ com.opensymphony.xwork2.ognl.ognlutil$2.execute(ognlutil.java:309) @ com.opensymphony.xwork2.ognl.ognlutil.compileandexecute(ognlutil.java:340) @ com.opensymphony.xwork2.ognl.ognlutil.getvalue(ognlutil.java:307) @ com.opensymphony.xwork2.defaultactioninvocation.invokeaction(defaultactioninvocation.java:423) @ com.opensymphony.xwork2.defaultactioninvocation.invokeactiononly(defaultactioninvocation.java:287) @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:250) @ com.inrev.bm.interceptor.irpermissioninterceptor.intercept(irpermissioninterceptor.java:56) @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:244) @ com.inrev.bm.interceptor.irappaccessinterceptor.intercept(irappaccessinterceptor.java:49) @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:244) @ com.inrev.bm.interceptor.irlogginginterceptor.intercept(irlogginginterceptor.java:432) @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:244) @ com.opensymphony.xwork2.interceptor.parametersinterceptor.dointercept(parametersinterceptor.java:229) @ com.opensymphony.xwork2.interceptor.methodfilterinterceptor.intercept(methodfilterinterceptor.java:98) @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:244) @ com.opensymphony.xwork2.interceptor.parametersinterceptor.dointercept(parametersinterceptor.java:229) @ com.opensymphony.xwork2.interceptor.methodfilterinterceptor.intercept(methodfilterinterceptor.java:98) @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:244) @ com.opensymphony.xwork2.interceptor.staticparametersinterceptor.intercept(staticparametersinterceptor.java:191) @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:244) @ org.apache.struts2.interceptor.multiselectinterceptor.intercept(multiselectinterceptor.java:73) @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:244) @ org.apache.struts2.interceptor.checkboxinterceptor.intercept(checkboxinterceptor.java:91) @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:244) @ org.apache.struts2.interceptor.fileuploadinterceptor.intercept(fileuploadinterceptor.java:253) @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:244) @ com.opensymphony.xwork2.interceptor.modeldriveninterceptor.intercept(modeldriveninterceptor.java:100) @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:244) @ com.opensymphony.xwork2.interceptor.scopedmodeldriveninterceptor.intercept(scopedmodeldriveninterceptor.java:141) @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:244) @ org.apache.struts2.interceptor.debugging.debugginginterceptor.intercept(debugginginterceptor.java:256) @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:244) @ com.opensymphony.xwork2.interceptor.chaininginterceptor.intercept(chaininginterceptor.java:145) @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:244) @ com.opensymphony.xwork2.interceptor.prepareinterceptor.dointercept(prepareinterceptor.java:171) @ com.opensymphony.xwork2.interceptor.methodfilterinterceptor.intercept(methodfilterinterceptor.java:98) @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:244) @ com.opensymphony.xwork2.interceptor.i18ninterceptor.intercept(i18ninterceptor.java:139) @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:244) @ org.apache.struts2.interceptor.servletconfiginterceptor.intercept(servletconfiginterceptor.java:164) @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:244) @ com.opensymphony.xwork2.interceptor.aliasinterceptor.intercept(aliasinterceptor.java:193) @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:244) @ com.opensymphony.xwork2.interceptor.exceptionmappinginterceptor.intercept(exceptionmappinginterceptor.java:189) @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:244) @ org.apache.struts2.impl.strutsactionproxy.execute(strutsactionproxy.java:54) @ org.apache.struts2.dispatcher.dispatcher.serviceaction(dispatcher.java:564) @ org.apache.struts2.dispatcher.ng.executeoperations.executeaction(executeoperations.java:81) @ org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter.dofilter(strutsprepareandexecutefilter.java:99) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.springframework.web.filter.characterencodingfilter.dofilterinternal(characterencodingfilter.java:88) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ com.s360.xssfilter.xssfilter.dofilter(xssfilter.java:19) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:220) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:122) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:505) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:170) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:103) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:956) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:116) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:423) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1079) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:625) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:316) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(thread.java:745)
caused by:
com.mysql.jdbc.exceptions.jdbc4.mysqlsyntaxerrorexception: have error in sql syntax; check manual corresponds mysql server version right syntax use near '0001' @ line 1 @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:57) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) @ java.lang.reflect.constructor.newinstance(constructor.java:526) @ com.mysql.jdbc.util.handlenewinstance(util.java:411) @ com.mysql.jdbc.util.getinstance(util.java:386) @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:1053) @ com.mysql.jdbc.mysqlio.checkerrorpacket(mysqlio.java:4120) @ com.mysql.jdbc.mysqlio.checkerrorpacket(mysqlio.java:4052) @ com.mysql.jdbc.mysqlio.sendcommand(mysqlio.java:2503) @ com.mysql.jdbc.mysqlio.sqlquerydirect(mysqlio.java:2664) @ com.mysql.jdbc.connectionimpl.execsql(connectionimpl.java:2794) @ com.mysql.jdbc.preparedstatement.executeinternal(preparedstatement.java:2155) @ com.mysql.jdbc.preparedstatement.executeupdate(preparedstatement.java:2458) @ com.mysql.jdbc.preparedstatement.executeupdate(preparedstatement.java:2375) @ com.mysql.jdbc.preparedstatement.executeupdate(preparedstatement.java:2359) @ org.apache.tomcat.dbcp.dbcp.delegatingpreparedstatement.executeupdate(delegatingpreparedstatement.java:105) @ org.apache.tomcat.dbcp.dbcp.delegatingpreparedstatement.executeupdate(delegatingpreparedstatement.java:105) @ org.hibernate.id.identitygenerator$getgeneratedkeysdelegate.executeandextract(identitygenerator.java:94) @ org.hibernate.id.insert.abstractreturningdelegate.performinsert(abstractreturningdelegate.java:57) ... 103 more
where i'm wrong in code? me please.
mapping database column types java types performed hibernate mapping configuration uses java types.
<property name="day" type="java.util.date"> <column name="day" not-null="true" /> </property> <property name="festival" type="java.lang.string"> <column name="festival" /> </property>
the missing </property>
added.
Comments
Post a Comment