I try to modify about 14 REST entitys at the same time.
The first few modifcations are successfull (and some in between), some others fail by occasionally HibernateException.
This is my 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() {
}
}
And this is the handle-method:
@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(...);
This is the logging output:
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
I use hibernate-envers:5.4.3-final, Hibernate-core:5.4.3-final and Spring-tx-5.1.7-Release
Theese requests are not successfull:
All other requests are successfull.
This is the stacktrace:
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
Why are some not successfull?
I found a suppressed exception:
Its pointed out that the exception is a bug inside hibernate or spring-tx hiding the original exception (row updated meanwhile-problem).
So the answer is to put them in a synchonized method:
private synchronized void handle(HttpServletResponse res,
HttpServletRequest req, RESTEntityModifier bean) throws Exception {
bean.handle(req, res);
}