Postgresql / Hibernate - 大对象可能无法在自动提交模式下使用

时间:2017-08-18 14:38:11

标签: java postgresql hibernate

最近我将我的应用程序从Oracle迁移到PostgreSql(9.2.20)。我使用org.hibernate.type.MaterializedBlobType在DB:

中存储文档内容(bytes属性)
<hibernate-mapping >
  <class name="x.y.z.entities.DocumentDataEntity" table="ds_document_data">
    <id name="id" column="id_" type="java.lang.String">
      <generator class="uuid2"/>
    </id>
    <property name="bytes" column="BYTES_" type="org.hibernate.type.MaterializedBlobType"/>
  </class>
</hibernate-mapping>
bytes类中的

DocumentDataEntity属性:

private byte[] bytes;

Oracle中工作正常,但在PostgreSql中,加载DocumentDataEntity会引发此异常:

18:54:57 ERROR [ds/root] i.a.w.c.d.e.ApplicationExceptionHandler -| Error occured in calling rest method! org.postgresql.util.PSQLException: Large Objects may not be used in auto-commit mode.
    at org.postgresql.largeobject.LargeObjectManager.open(LargeObjectManager.java:265)
    at org.postgresql.largeobject.LargeObjectManager.open(LargeObjectManager.java:251)
    at org.postgresql.jdbc.AbstractBlobClob.getLo(AbstractBlobClob.java:283)
    at org.postgresql.jdbc.AbstractBlobClob.getBinaryStream(AbstractBlobClob.java:127)
    at org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor.wrap(PrimitiveByteArrayTypeDescriptor.java:115)
    ... 163 common frames omitted
Wrapped by: org.hibernate.HibernateException: Unable to access lob stream
    at org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor.wrap(PrimitiveByteArrayTypeDescriptor.java:118)
    at org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor.wrap(PrimitiveByteArrayTypeDescriptor.java:26)
    at org.hibernate.type.descriptor.sql.BlobTypeDescriptor$1.doExtract(BlobTypeDescriptor.java:48)
    at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:238)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:234)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:224)
    at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:300)
    at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2790)
    at org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.loadFromResultSet(EntityReferenceInitializerImpl.java:306)
    at org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.hydrateEntityState(EntityReferenceInitializerImpl.java:233)
    at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.readRow(AbstractRowReader.java:103)
    at org.hibernate.loader.plan.exec.internal.EntityLoadQueryDetails$EntityLoaderRowReader.readRow(EntityLoadQueryDetails.java:239)
    at org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:122)
    at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:122)
    at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:86)
    at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:167)
    at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4019)
    at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508)
    at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478)
    at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219)
    at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:116)
    at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89)
    at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1129)
    at org.hibernate.internal.SessionImpl.immediateLoad(SessionImpl.java:997)
    at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:157)
    at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:266)
    at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:73)

注意:

  • 我正在使用Spring(4.3.8.RELEASE)和Hibernate(5.0.12.Final)。
  • 我在@Transactional bean的DocumentDataManager方法中使用了load注释。
  • 保存/加载在Oracle
  • 中正常工作

0 个答案:

没有答案