如何保持BLOB对象

来源:3-4 [Hibernate单表操作] 对象类型

car

2016-10-03 21:44

- SQL Error: 17090, SQLState: null
- 不允许的操作: streams type cannot be used in batching
- Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: could not insert: [Students]
 at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
 at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
 at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
 at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2078)
 at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2427)
 at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
 at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
 at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
 at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
 at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
 at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
 at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
 at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
 at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
 at StudentsTest.tearDown(StudentsTest.java:34)
 at junit.framework.TestCase.runBare(TestCase.java:136)
 at junit.framework.TestResult$1.protect(TestResult.java:106)
 at junit.framework.TestResult.runProtected(TestResult.java:124)
 at junit.framework.TestResult.run(TestResult.java:109)
 at junit.framework.TestCase.run(TestCase.java:120)
 at junit.framework.TestSuite.runTest(TestSuite.java:230)
 at junit.framework.TestSuite.run(TestSuite.java:225)
 at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.sql.SQLException: 不允许的操作: streams type cannot be used in batching
 at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
 at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
 at oracle.jdbc.driver.OraclePreparedStatement.addBatch(OraclePreparedStatement.java:3775)
 at org.hibernate.jdbc.BatchingBatcher.addToBatch(BatchingBatcher.java:30)
 at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2062)
 ... 24 more


部分代码是这样写的

  InputStream input = new FileInputStream(file);
  byte[] byteArray = new byte[input.available()];
  input.read(byteArray);
  input.close();
  Students students = new Students("张三丰", "男", new Date(), "武当山");
  Blob pictrue = Hibernate.createBlob(byteArray);
 students.setPictrue(pictrue);
 System.out.println(students.getPictrue());
 session.save(students);
写回答 关注

3回答

  • qq_杰娃儿_04070083
    2016-10-05 10:21:19
    已采纳

    哦,我直接用的它给的jar包,就可以的。Blob pictrue = Hibernate.createBlob(byteArray);这里是不是应该传input进来呢?,因为图片文件在input里面。

  • yo_te_amo
    2016-10-17 10:17:06

    我也出错了难受

  • qq_杰娃儿_04070083
    2016-10-05 01:07:03

    兄弟,Hibernate.createBlob(byteArray);这个方法好像没有啊?可以通过编译?

    car

    有,是hibernate3.x的

    2016-10-05 09:47:58

    共 1 条回复 >

Hibernate初探之单表映射

Java持久化框架Hibernate入门教程,掌握Hibernate基本概念

74810 学习 · 793 问题

查看课程

相似问题