jpa - entityManager.persist(entity) hibernate Exception -
i'm getting following hibernate exception when trying use entitymanager.persist(entity)
method. , i've made sure i've correctly formated date
or time
attributes in show
class.
javax.persistence.persistenceexception: org.hibernate.exception.sqlgrammarexception: not execute statement @ org.hibernate.ejb.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1387) @ org.hibernate.ejb.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1310) @ org.hibernate.ejb.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1316) @ org.hibernate.ejb.abstractentitymanagerimpl.persist(abstractentitymanagerimpl.java:881) @ 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:601) @ org.springframework.orm.jpa.sharedentitymanagercreator$sharedentitymanagerinvocationhandler.invoke(sharedentitymanagercreator.java:241) @ com.sun.proxy.$proxy23.persist(unknown source) @ persistence.jpamanagershowdao.addshow(jpamanagershowdao.java:102) @ 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:601) @ org.springframework.aop.support.aoputils.invokejoinpointusingreflection(aoputils.java:317) @ org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:198) @ com.sun.proxy.$proxy24.addshow(unknown source) @ persistence.jpamanagershowdaotest.testaddshow(jpamanagershowdaotest.java:24) @ 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:601) @ org.junit.runners.model.frameworkmethod$1.runreflectivecall(frameworkmethod.java:45) @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:15) @ org.junit.runners.model.frameworkmethod.invokeexplosively(frameworkmethod.java:42) @ org.junit.internal.runners.statements.invokemethod.evaluate(invokemethod.java:20) @ org.springframework.test.context.junit4.statements.runbeforetestmethodcallbacks.evaluate(runbeforetestmethodcallbacks.java:74) @ org.springframework.test.context.junit4.statements.runaftertestmethodcallbacks.evaluate(runaftertestmethodcallbacks.java:83) @ org.springframework.test.context.junit4.statements.springrepeat.evaluate(springrepeat.java:72) @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:231) @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:88) @ org.junit.runners.parentrunner$3.run(parentrunner.java:231) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:60) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:229) @ org.junit.runners.parentrunner.access$000(parentrunner.java:50) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:222) @ org.springframework.test.context.junit4.statements.runbeforetestclasscallbacks.evaluate(runbeforetestclasscallbacks.java:61) @ org.springframework.test.context.junit4.statements.runaftertestclasscallbacks.evaluate(runaftertestclasscallbacks.java:71) @ org.junit.runners.parentrunner.run(parentrunner.java:300) @ org.springframework.test.context.junit4.springjunit4classrunner.run(springjunit4classrunner.java:174) @ org.eclipse.jdt.internal.junit4.runner.junit4testreference.run(junit4testreference.java:50) @ org.eclipse.jdt.internal.junit.runner.testexecution.run(testexecution.java:38) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:467) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:683) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.run(remotetestrunner.java:390) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.main(remotetestrunner.java:197) caused by: org.hibernate.exception.sqlgrammarexception: not execute statement @ org.hibernate.exception.internal.sqlexceptiontypedelegate.convert(sqlexceptiontypedelegate.java:82) @ org.hibernate.exception.internal.standardsqlexceptionconverter.convert(standardsqlexceptionconverter.java:49) @ org.hibernate.engine.jdbc.spi.sqlexceptionhelper.convert(sqlexceptionhelper.java:125) @ org.hibernate.engine.jdbc.spi.sqlexceptionhelper.convert(sqlexceptionhelper.java:110) @ org.hibernate.engine.jdbc.internal.resultsetreturnimpl.executeupdate(resultsetreturnimpl.java:136) @ org.hibernate.id.identitygenerator$getgeneratedkeysdelegate.executeandextract(identitygenerator.java:96) @ org.hibernate.id.insert.abstractreturningdelegate.performinsert(abstractreturningdelegate.java:58) @ org.hibernate.persister.entity.abstractentitypersister.insert(abstractentitypersister.java:2975) @ org.hibernate.persister.entity.abstractentitypersister.insert(abstractentitypersister.java:3487) @ org.hibernate.action.internal.entityidentityinsertaction.execute(entityidentityinsertaction.java:81) @ org.hibernate.engine.spi.actionqueue.execute(actionqueue.java:364) @ org.hibernate.engine.spi.actionqueue.addresolvedentityinsertaction(actionqueue.java:205) @ org.hibernate.engine.spi.actionqueue.addinsertaction(actionqueue.java:185) @ org.hibernate.engine.spi.actionqueue.addaction(actionqueue.java:169) @ org.hibernate.event.internal.abstractsaveeventlistener.addinsertaction(abstractsaveeventlistener.java:321) @ org.hibernate.event.internal.abstractsaveeventlistener.performsaveorreplicate(abstractsaveeventlistener.java:286) @ org.hibernate.event.internal.abstractsaveeventlistener.performsave(abstractsaveeventlistener.java:192) @ org.hibernate.event.internal.abstractsaveeventlistener.savewithgeneratedid(abstractsaveeventlistener.java:125) @ org.hibernate.ejb.event.ejb3persisteventlistener.savewithgeneratedid(ejb3persisteventlistener.java:78) @ org.hibernate.event.internal.defaultpersisteventlistener.entityistransient(defaultpersisteventlistener.java:208) @ org.hibernate.event.internal.defaultpersisteventlistener.onpersist(defaultpersisteventlistener.java:151) @ org.hibernate.event.internal.defaultpersisteventlistener.onpersist(defaultpersisteventlistener.java:78) @ org.hibernate.internal.sessionimpl.firepersist(sessionimpl.java:853) @ org.hibernate.internal.sessionimpl.persist(sessionimpl.java:827) @ org.hibernate.internal.sessionimpl.persist(sessionimpl.java:831) @ org.hibernate.ejb.abstractentitymanagerimpl.persist(abstractentitymanagerimpl.java:875) ... 43 more caused by: com.mysql.jdbc.exceptions.jdbc4.mysqlsyntaxerrorexception: have error in sql syntax; check manual corresponds mysql server version right syntax use near 'show (enddate, endtime, showname, startdate, starttime, ticketprice) values ('20' @ 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:525) @ com.mysql.jdbc.util.handlenewinstance(util.java:411) @ com.mysql.jdbc.util.getinstance(util.java:386) @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:1054) @ 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:2815) @ 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.commons.dbcp.delegatingpreparedstatement.executeupdate(delegatingpreparedstatement.java:105) @ org.apache.commons.dbcp.delegatingpreparedstatement.executeupdate(delegatingpreparedstatement.java:105) @ org.hibernate.engine.jdbc.internal.resultsetreturnimpl.executeupdate(resultsetreturnimpl.java:133)
code:
@entity public class show implements serializable { private static final long serialversionuid = 1l; @id @generatedvalue(strategy=generationtype.auto) private int idshow; @column(name="enddate") private date enddate; private time endtime; private string showname; @column(name="startdate") private date startdate; private time starttime; private int ticketprice; @onetomany(mappedby="show",cascade=cascadetype.all) private list<place> places; public list<place> getplaces() { return this.places; } public void setplaces(list<place> places) { this.places = places; } public show() { } public int getidshow() { return this.idshow; } public void setidshow(int idshow) { this.idshow = idshow; } public date getenddate() { return this.enddate; } public void setenddate(date enddate) { this.enddate = enddate; } public time getendtime() { return this.endtime; } public void setendtime(time endtime) { this.endtime = endtime; } public string getshowname() { return this.showname; } public void setshowname(string showname) { this.showname = showname; } public date getstartdate() { return this.startdate; } public void setstartdate(date startdate) { this.startdate = startdate; } public time getstarttime() { return this.starttime; } public void setstarttime(time starttime) { this.starttime = starttime; } public int getticketprice() { return this.ticketprice; } public void setticketprice(int ticketprice) { this.ticketprice = ticketprice; } }
code 2:
@override public void addshow(string showname, string enddate, string startdate, string starttime, string endtime, int ticketprice) throws appexception { show=new show(); system.out.println(show.getidshow()); show.setshowname(showname); try { date end=date.valueof(enddate); show.setenddate(end); system.out.println(show.getenddate()); } catch (exception e) { // todo auto-generated catch block throw new appexception("db exception : invalid date format"); } try{ date start=date.valueof(startdate); show.setstartdate(start); }catch(exception e){ throw new appexception("db exception : invalid date format"); } try{ time timestart=time.valueof(starttime); show.setstarttime(timestart); }catch(exception e){ throw new appexception("db exception : invalid time format"); } try{ time timeend=time.valueof(endtime); show.setendtime(timeend); }catch(exception e){ throw new appexception("db exception : invalid time format"); } show.setticketprice(ticketprice); entitymanager.persist(show); }
show
reserved mysql keyword. change name of table.
Comments
Post a Comment