gpt4 book ai didi

java - 偶尔出现 HibernateException

转载 作者:行者123 更新时间:2023-12-02 04:19:16 24 4
gpt4 key购买 nike

我尝试同时修改大约 14 个 REST 实体。

前几次修改是成功的(以及中间的一些修改),其他一些修改偶尔会失败,出现 HibernateException。

这是我的 servlet:

public class ReSTAPIFilter implements Filter {

@Override
public void init(FilterConfig filterConfig) throws ServletException {
}

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) {
HttpServletResponse res = (HttpServletResponse) response;
HttpServletRequest req = (HttpServletRequest) request;

AnnotationConfigWebApplicationContext ctx = (AnnotationConfigWebApplicationContext) request
.getServletContext()
.getAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.Restful-Spring");
RESTEntityModifier bean = ctx.getBean(RESTEntityModifier.class);
if (bean.canHandle(req)) {
try {
bean.handle(req, res);
return;
} catch (Exception e) {
System.out.println(
req.getRequestURI() + "-T" + Thread.currentThread().hashCode() + " - " + e.getMessage());
return;
}
}
}
chain.doFilter(request, response);
}

@Override
public void destroy() {
}
}

这是句柄方法:

@Transactional
public void handle(HttpServletRequest r, HttpServletResponse response) throws Exception {
LOG.fine("Handle " + r.getMethod() + " " + r.getRequestURL() + " - Transaction: "
+ TransactionAspectSupport.currentTransactionStatus() + " T" + Thread.currentThread().hashCode());
entityManager.persist(...);

这是日志输出:

2019-06-18 11:32:15 FEIN x.web.rm.RESTEntityModifier handle Handle POST https://localhost/X/rest/BuildResult - Transaction: org.springframework.transaction.support.DefaultTransactionStatus@3b6dbbb5 T1440613991
2019-06-18 11:32:15 FEIN x.web.rm.RESTEntityModifier handle Handle PUT https://localhost/x/rest/buildResult/202/params - Transaction: org.springframework.transaction.support.DefaultTransactionStatus@51269d65 T1440613991
2019-06-18 11:32:15 FEIN x.web.rm.RESTEntityModifier handle Handle PUT https://localhost/x/rest/buildResult/202/params - Transaction: org.springframework.transaction.support.DefaultTransactionStatus@74e3d56b T590958110
2019-06-18 11:32:15 FEIN x.web.rm.RESTEntityModifier handle Handle PUT https://localhost/x/rest/buildResult/202/params - Transaction: org.springframework.transaction.support.DefaultTransactionStatus@2d07e97b T1576512215
2019-06-18 11:32:15 FEIN x.web.rm.RESTEntityModifier handle Handle PUT https://localhost/x/rest/buildResult/202/params - Transaction: org.springframework.transaction.support.DefaultTransactionStatus@3652c837 T590958110
2019-06-18 11:32:15 INFO org.hibernate.event.internal.DefaultLoadEventListener doOnLoad HHH000327: Error performing load command : org.hibernate.HibernateException: Unable to access lob stream
2019-06-18 11:32:15 INFO org.hibernate.event.internal.DefaultLoadEventListener doOnLoad HHH000327: Error performing load command : org.hibernate.HibernateException: Unable to access lob stream
2019-06-18 11:32:15 FEIN x.web.rm.RESTEntityModifier handle Handle PUT https://localhost/x/rest/buildResult/202/params - Transaction: org.springframework.transaction.support.DefaultTransactionStatus@684c4367 T590958110
/x/rest/buildResult/202/params-T1440613991 - Unable to access lob stream; nested exception is org.hibernate.HibernateException: Unable to access lob stream
/x/rest/buildResult/202/params-T1576512215 - Unable to access lob stream; nested exception is org.hibernate.HibernateException: Unable to access lob stream
2019-06-18 11:32:15 FEIN x.web.rm.RESTEntityModifier handle Handle PUT https://localhost/x/rest/buildResult/202/params - Transaction: org.springframework.transaction.support.DefaultTransactionStatus@571090c6 T1395592956
2019-06-18 11:32:15 FEIN x.web.rm.RESTEntityModifier handle Handle PUT https://localhost/x/rest/buildResult/202/params - Transaction: org.springframework.transaction.support.DefaultTransactionStatus@3b12eb0 T1440613991
2019-06-18 11:32:15 FEIN x.web.rm.RESTEntityModifier handle Handle PUT https://localhost/x/rest/buildResult/202/params - Transaction: org.springframework.transaction.support.DefaultTransactionStatus@5dd9b196 T590958110
2019-06-18 11:32:15 INFO org.hibernate.event.internal.DefaultLoadEventListener doOnLoad HHH000327: Error performing load command : org.hibernate.HibernateException: Unable to access lob stream
/x/rest/buildResult/202/params-T1395592956 - Unable to access lob stream; nested exception is org.hibernate.HibernateException: Unable to access lob stream
2019-06-18 11:32:15 FEIN x.web.rm.RESTEntityModifier handle Handle PUT https://localhost/x/rest/buildResult/202/params - Transaction: org.springframework.transaction.support.DefaultTransactionStatus@1ac1fbe9 T1395592956
2019-06-18 11:32:15 INFO org.hibernate.event.internal.DefaultLoadEventListener doOnLoad HHH000327: Error performing load command : org.hibernate.HibernateException: Unable to access lob stream
/x/rest/buildResult/202/params-T1440613991 - Unable to access lob stream; nested exception is org.hibernate.HibernateException: Unable to access lob stream
2019-06-18 11:32:15 FEIN x.web.rm.RESTEntityModifier handle Handle PUT https://localhost/x/rest/buildResult/202/params - Transaction: org.springframework.transaction.support.DefaultTransactionStatus@ba7efb6 T1440613991
2019-06-18 11:32:15 FEIN x.web.rm.RESTEntityModifier handle Handle PUT https://localhost/x/rest/buildResult/202/params - Transaction: org.springframework.transaction.support.DefaultTransactionStatus@7dabe5fc T590958110
2019-06-18 11:32:15 INFO org.hibernate.event.internal.DefaultLoadEventListener doOnLoad HHH000327: Error performing load command : org.hibernate.HibernateException: Unable to access lob stream
/x/rest/buildResult/202/params-T1395592956 - Unable to access lob stream; nested exception is org.hibernate.HibernateException: Unable to access lob stream
2019-06-18 11:32:16 FEIN x.web.rm.RESTEntityModifier handle Handle PUT https://localhost/x/rest/buildResult/202/params - Transaction: org.springframework.transaction.support.DefaultTransactionStatus@5df4cf5e T1395592956
2019-06-18 11:32:16 FEIN x.web.rm.RESTEntityModifier handle Handle PUT https://localhost/x/rest/buildResult/202/params - Transaction: org.springframework.transaction.support.DefaultTransactionStatus@279dc900 T590958110
2019-06-18 11:32:16 INFO org.hibernate.event.internal.DefaultLoadEventListener doOnLoad HHH000327: Error performing load command : org.hibernate.HibernateException: Unable to access lob stream
/x/rest/buildResult/202/params-T1395592956 - Unable to access lob stream; nested exception is org.hibernate.HibernateException: Unable to access lob stream
2019-06-18 11:32:16 INFO org.hibernate.event.internal.DefaultLoadEventListener doOnLoad HHH000327: Error performing load command : org.hibernate.HibernateException: Unable to access lob stream
2019-06-18 11:32:16 FEIN x.web.rm.RESTEntityModifier handle Handle PUT https://localhost/x/rest/buildResult/202/params - Transaction: org.springframework.transaction.support.DefaultTransactionStatus@fa7fdbd T1395592956
/x/rest/buildResult/202/params-T1440613991 - Unable to access lob stream; nested exception is org.hibernate.HibernateException: Unable to access lob stream
2019-06-18 11:32:16 FEIN x.web.rm.RESTEntityModifier handle Handle PUT https://localhost/x/rest/buildResult/202/params - Transaction: org.springframework.transaction.support.DefaultTransactionStatus@b0f4477 T1440613991
2019-06-18 11:32:16 FEIN x.web.rm.RESTEntityModifier handle Handle PUT https://localhost/x/rest/buildResult/202/params - Transaction: org.springframework.transaction.support.DefaultTransactionStatus@4026ebe4 T384544935
2019-06-18 11:32:16 INFO org.hibernate.event.internal.DefaultLoadEventListener doOnLoad HHH000327: Error performing load command : org.hibernate.HibernateException: Unable to access lob stream
/x/rest/buildResult/202/params-T1395592956 - Unable to access lob stream; nested exception is org.hibernate.HibernateException: Unable to access lob stream
2019-06-18 11:32:16 INFO org.hibernate.event.internal.DefaultLoadEventListener doOnLoad HHH000327: Error performing load command : org.hibernate.HibernateException: Unable to access lob stream
/x/rest/buildResult/202/params-T1440613991 - Unable to access lob stream; nested exception is org.hibernate.HibernateException: Unable to access lob stream
2019-06-18 11:32:16 FEIN x.web.rm.RESTEntityModifier handle Handle PATCH https://localhost/x/buildResult/202/finished - Transaction: org.springframework.transaction.support.DefaultTransactionStatus@415fd4ad T384544935

我使用 hibernate-envers:5.4.3-final、Hibernate-core:5.4.3-final 和 Spring-tx-5.1.7-Release

这些请求成功:

  • 主题#1440613991
  • 主题#1576512215
  • 主题#1395592956

所有其他请求均成功。

这是堆栈跟踪:

org.springframework.orm.jpa.JpaSystemException: Unable to access lob stream; nested exception is org.hibernate.HibernateException: Unable to access lob stream
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:407)
at org.springframework.orm.jpa.DefaultJpaDialect.translateExceptionIfPossible(DefaultJpaDialect.java:127)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:545)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:746)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:714)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:534)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:305)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
at X.RESTEntityModifier$$EnhancerBySpringCGLIB$$b9cd3ce3.handle(<generated>)
at X.ReSTAPIFilter$1.run(ReSTAPIFilter.java:39)
Caused by: org.hibernate.HibernateException: Unable to access lob stream
at org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor.wrap(PrimitiveByteArrayTypeDescriptor.java:123)
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:257)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:253)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:243)
at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:329)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:3014)
at org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.loadFromResultSet(EntityReferenceInitializerImpl.java:305)
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:254)
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:197)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4278)
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:480)
at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:450)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:201)
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:260)
at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:103)
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:71)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1286)
at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1163)
at org.hibernate.internal.ExceptionConverterImpl.wrapStaleStateException(ExceptionConverterImpl.java:220)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:93)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181)
at org.hibernate.internal.ExceptionConverterImpl.convertCommitException(ExceptionConverterImpl.java:65)
at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:107)
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:532)
... 9 more
Caused by: org.postgresql.util.PSQLException: LargeObjects (LOB) dürfen im Modus 'auto-commit' nicht verwendet werden.
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:120)
... 40 more

为什么有些不成功?

最佳答案

我发现了一个被抑制的异常:

它指出该异常是 hibernate 或 spring-tx 内部的错误,隐藏了原始异常(同时更新行问题)。

enter image description here

所以答案是将它们放入同步方法中:

private synchronized void handle(HttpServletResponse res, 
HttpServletRequest req, RESTEntityModifier bean) throws Exception {
bean.handle(req, res);
}

关于java - 偶尔出现 HibernateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56646309/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com