问题描述
org.hibernate.exception.SQLGrammarException:YouhaveanerrorinyourSQLsyntax;checkthemanualthatcorrespondstoyourMySQLserverversionfortherightsyntaxtousenear'?1姯?-駭0⒗S=i偋??G伤G?翤篘+O綨'O糿視剈股摦+縶怽'???[08榅?f'atline1用blob类型存储图片时,出现以上异常,字段检查无误,没有包含关键字存储文本可以,存储图片就不行映射文件如下:<?xmlversion="1.0"?><!DOCTYPEhibernate-mappingPUBLIC"-//Hibernate/HibernateMappingDTD3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><!--Generated2014-8-711:22:19byHibernateTools3.4.0.CR1--><hibernate-mapping><classname="txlong.hibernate.pojo.Student"table="students"lazy="false"><idname="studentId"type="java.lang.Integer"><columnname="student_id"/><generatorclass="native"/></id><propertyname="studentName"type="java.lang.String"><columnname="student_name"length="16"/></property><propertyname="studentAge"type="java.lang.Integer"><columnname="student_age"/></property><propertyname="studentImage"type="java.sql.Blob"><columnname="student_image"></column></property><propertyname="studentIntro"><columnname="student_introduction"></column></property><setname="schoolsStudied"table="schools"inverse="false"cascade="all"><key><columnname="student_id"/></key><one-to-manyclass="txlong.hibernate.pojo.School"/></set></class></hibernate-mapping>测试代码如下:publicclassHibernateTest{SessionFactorysessionFactory;Transactiontransaction;Sessionsession;@Beforepublicvoidinit(){Configurationconfiguration=newConfiguration().configure();ServiceRegistryservice=newServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();sessionFactory=configuration.buildSessionFactory(service);session=sessionFactory.openSession();transaction=session.beginTransaction();}@AfterpublicvoidDestroyable(){transaction.commit();session.close();sessionFactory.close();}@TestpublicvoidtestSave()throwsIOException{Schoolschool1=newSchool("edu","china");Schoolschool2=newSchool("ytu","assdff");Studentstudent=newStudent();student.setStudentName("Billy");student.setStudentAge(22);Filefile=newFile("D:\image.zip");InputStreamin=newFileInputStream(file);Blobimage=Hibernate.getLobCreator(session).createBlob(in,in.available());student.setStudentImage(image);Clobintro=Hibernate.getLobCreator(session).createClob("高三二班");student.setStudentIntro(intro);student.getSchoolsStudied().add(school1);student.getSchoolsStudied().add(school2);session.save(student);}}详细异常如下:org.hibernate.exception.SQLGrammarException:YouhaveanerrorinyourSQLsyntax;checkthemanualthatcorrespondstoyourMySQLserverversionfortherightsyntaxtousenear'?1姯?-駭0⒗S=i偋??G伤G?翤篘+O綨'O糿視剈股摦+縶怽'???[08榅?f'atline1atorg.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:83)atorg.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)atorg.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)atorg.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)atorg.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)atorg.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)atcom.sun.proxy.$Proxy8.executeUpdate(UnknownSource)atorg.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:96)atorg.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:58)atorg.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2765)atorg.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3276)atorg.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)atorg.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)atorg.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:203)atorg.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:183)atorg.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:167)atorg.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:320)atorg.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:287)atorg.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:193)atorg.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:126)atorg.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:204)atorg.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)atorg.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:189)atorg.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)atorg.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)atorg.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:670)atorg.hibernate.internal.SessionImpl.save(SessionImpl.java:662)atorg.hibernate.internal.SessionImpl.save(SessionImpl.java:658)attxlong.hibernate.test.HibernateTest.testSave(HibernateTest.java:67)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(UnknownSource)atsun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownSource)atjava.lang.reflect.Method.invoke(UnknownSource)atorg.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)atorg.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)atorg.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)atorg.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)atorg.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)atorg.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)atorg.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)atorg.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)atorg.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)atorg.junit.runners.ParentRunner$3.run(ParentRunner.java:238)atorg.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)atorg.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)atorg.junit.runners.ParentRunner.access$000(ParentRunner.java:53)atorg.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)atorg.junit.runners.ParentRunner.run(ParentRunner.java:309)atorg.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)atorg.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)......