错误:org.hibernate.exception.GenericJDBCException:无法提取ResultSet

时间:2019-03-15 14:12:37

标签: java hibernate java-ee

我对数据库执行许多请求时遇到错误。 当我在“应用程序”上的位置/按钮上多次单击时,出现错误。 一切正常,直到用户在应用程序中多次单击。

有人可以帮助我解决此错误吗?

我的persistence.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">

    <persistence-unit name="XXXXXXXXXX1" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL95Dialect" />
            <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/threeptdb" />
            <property name="javax.persistence.jdbc.user" value="YYYYYYUser" />
            <property name="javax.persistence.jdbc.password" value="YYYYYYPass" />

            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="false" />
            <property name="hibernate.use_sql_comments" value="false" />
            <property name="hibernate.jdbc.wrap_result_sets" value="false" />
            <property name="hibernate.hibernate.cache.use_query_cache" value="true" />
            <property name="hibernate.hbm2ddl.auto" value="update" />
        </properties>
    </persistence-unit>

    <persistence-unit name="XXXXXXXXXX2" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
            <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@site.server.net:1111:xxxxxx" />
            <property name="javax.persistence.jdbc.user" value="XXXXXXXXXXUser" />
            <property name="javax.persistence.jdbc.password" value="XXXXXXXXXXPass" />

            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="false" />
            <property name="hibernate.use_sql_comments" value="false" />
            <property name="hibernate.jdbc.wrap_result_sets" value="false" />
            <property name="hibernate.hibernate.cache.use_query_cache" value="true" />
        </properties>
    </persistence-unit>

</persistence>

这是我使用的实体类的示例:

@Entity
@Table(name = "primes", schema="public")
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public final class PrimeEntity extends PlanItemEntity {

    @Builder(toBuilder = true)
    public PrimeEntity(Long id,
                       String swpId,
                       String name,
                       String status,
                       String version,
                       Long itTarget,
                       Long bizTarget,
                       List<DomainEntity> domains,
                       String description,
                       String itOwner,
                       String bizOwner,
                       ZonedDateTime excelUpdate) {
        super(id, swpId, name, status, version, itOwner, bizOwner);
        this.itTarget = itTarget;
        this.bizTarget = bizTarget;
        this.domains = domains == null ? new LinkedList<>() : domains;
        this.description = description;
        this.excelUpdate = excelUpdate;
    }

    @Column(name = "it_target")
    private Long itTarget;

    @Column(name = "biz_target")
    private Long bizTarget;

    @Column(name="excel_update")
    private ZonedDateTime excelUpdate;

    @OneToMany(mappedBy = "prime", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @OrderBy("UPPER (name) ASC")
    private List<DomainEntity> domains = new LinkedList<>();

    @Column(columnDefinition = "TEXT")
    private String description;
}

错误日志:

2019-03-15T15:10:51.137+0000] [] [?[1;93mWARN?[0m] [] [?[1;94morg.hibernate.engine.jdbc.spi.SqlExceptionHelper?[0m] [tid: _ThreadID=38 _ThreadName=http-thread-pool::http-listener(9)] [timeMillis: 1552662651137] [levelValue: 900] SQL Error: 0, SQLState: 55000

[2019-03-15T15:10:51.138+0000] [] [?[1;91mERROR?[0m] [] [?[1;94morg.hibernate.engine.jdbc.spi.SqlExceptionHelper?[0m] [tid: _ThreadID=38 _ThreadName=http-thread-pool::http-listener(9)] [timeMillis: 1552662651138] [levelValue: 1000] This statement has been closed.

[2019-03-15T15:10:51.152+0000] [] [?[1;91mSEVERE?[0m] [] [?[1;94mfish.payara.microprofile.opentracing.jaxrs.JaxrsContainerRequestTracingFilter?[0m] [tid: _ThreadID=38 _ThreadName=http-thread-pool::http-listener(9)] [timeMillis: 1552662651152] [levelValue: 1000] [[
  javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not extract ResultSet
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not extract ResultSet
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181)
        at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1514)
        at org.hibernate.query.Query.getResultList(Query.java:135)
        at com.domain.application.user.UserRoleDao.findByItem(UserRoleDao.java:27)
        at com.domain.application.user.UserRoleService.retrieveByItem(UserRoleService.java:38)
        at com.domain.application.productcatalog.ProductCatalogService.setItemOwnership(ProductCatalogService.java:285)
        at com.domain.application.productcatalog.ProductCatalogService.retrieve(ProductCatalogService.java:87)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:76)
        at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:148)
        at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:191)
        at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:243)
        at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:103)
        at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:493)
        at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:415)
        at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:104)
        at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:277)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:272)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:268)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:316)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:298)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:268)
        at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289)
        at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:256)
        at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:704)
        at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:416)
        at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:370)
        at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389)
        at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342)
        at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229)
        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1628)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:258)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:755)
        at org.apache.catalina.core.StandardPipeline.doChainInvoke(StandardPipeline.java:579)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:371)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:238)
        at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:516)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:213)
        at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:182)
        at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:156)
        at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:218)
        at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:95)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:260)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:177)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:109)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:88)
        at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:53)
        at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:524)
        at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:89)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:94)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:33)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:114)
        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:569)
        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:549)
        at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.exception.GenericJDBCException: could not extract ResultSet
        at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:69)
        at org.hibernate.loader.Loader.getResultSet(Loader.java:2167)
        at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1930)
        at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1892)
        at org.hibernate.loader.Loader.doQuery(Loader.java:937)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:340)
        at org.hibernate.loader.Loader.doList(Loader.java:2689)
        at org.hibernate.loader.Loader.doList(Loader.java:2672)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2506)
        at org.hibernate.loader.Loader.list(Loader.java:2501)
        at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:504)
        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:395)
        at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:220)
        at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1508)
        at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1537)
        at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1505)
        ... 59 more
Caused by: org.postgresql.util.PSQLException: This statement has been closed.
        at org.postgresql.jdbc.PgStatement.checkClosed(PgStatement.java:694)
        at org.postgresql.jdbc.PgStatement.getMaxRows(PgStatement.java:501)
        at org.postgresql.jdbc.PgStatement.createResultSet(PgStatement.java:153)
        at org.postgresql.jdbc.PgStatement$StatementResultHandler.handleResultRows(PgStatement.java:204)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2120)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)
        at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
        at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
        at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:143)
        at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:106)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:60)
        ... 74 more
]]

1 个答案:

答案 0 :(得分:0)

当尝试一遍又一遍地执行相同的操作时,这似乎与异步处理有关; hibernate会在我们的实体上跟踪更改,这称为脏检查,并减少了编译查询所需的时间,默认情况下,它包含更新查询中的所有字段,而不是仅包含已更改的字段。

尝试阅读有关@DynamicUpdate和@OptimisticLock注释的信息。