数据库连接已经用尽,而Weblogic连接池则完美无缺

时间:2018-08-14 06:13:23

标签: java sql oracle hibernate stored-procedures

我遇到了一个典型的问题,其中WebLogic连接池的容量处于限制之下,但是Oracle DB连接不断增加,最终达到最大DB连接大小并停止响应。

我们正在使用hibernate调用数据库存储过程来更新数据库中的某些记录。

create or replace procedure UPDATE_TIME
(
   p_alarmId       NUMBER,
   p_clearTime     NUMBER
)
is
   v_errorCode NUMBER := 1;
begin
    while ( v_errorCode != 0 )
    loop
       v_errorCode := 0;
       begin

          update ANNOTATION
          set    PARTITION_TIME=p_clearTime 
          where ANN_ID = (select ANNOTATION_ID from CORE where ID = p_alarmId) and PARTITION_TIME = 0;

          exception
             when OTHERS then
               v_errorCode := 1;
       end;
    end loop;
end;
/

最后,WebLogic事务在5分钟后超时,因为如下所述指定了套接字超时,但是数据库连接永远不会免费。

<url>jdbc:mysql://localhost:31300/oneodb?socketTimeout=300000</url>

例外:

javax.ejb.EJBException: EJB Exception: ; nested exception is: 
    javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: could not execute native bulk manipulation query
...
        at Caused by: oracle.net.ns.NetException: Socket read timed out
        at oracle.net.ns.Packet.receive(Packet.java:339)

任何输入都是值得赞赏的。谢谢。

1 个答案:

答案 0 :(得分:0)

我们找到了问题的根本原因。

虽然db过程中的循环没有让原始异常抛出给应用程序。一旦删除此循环,就会捕获异常。

Caused by: java.sql.SQLException: ORA-01427: single-row subquery returns more than one row

在update命令中指定的内部查询返回2行,而预期只有1行。查询已更新,具有更多约束,并且工作正常。同样,该不必要的while循环也被删除。