JPA(EclipseLink)连接超时 [英] JPA (EclipseLink) connection timeouts

查看:393
本文介绍了JPA(EclipseLink)连接超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JPA 2.0与EclipseLink,Glassfish和NetBeans。我在长时间不活动后遇到连接超时的问题。我看起来很难找到方法:

I am using JPA 2.0 with EclipseLink, Glassfish, and NetBeans. I am experiencing issues with connection timeouts after extended periods of inactivity. I've looked pretty hard for ways to either:

(1)检查JPA的连接,然后断开连接后重新建立连接

(1) Check for JPA's connection and then re-establish its connection if disconnected

(2)保持JPA的连接尽可能活跃

(2) Keep the JPA's connection active as much as possible

但是,我真的找不到一个解决方案。我能找到的最接近的东西是这篇文章:如何修改Eclipselink JPA 2.0连接重试行为

However, I can't really find a solution for either. The closest thing I can find is this post: How To modify Eclipselink JPA 2.0 connection retry behavior .

如果有直接使用JPA的连接,它会很好,但它埋在库。

If there is someway to directly work with the JPA's connection, it'd be nice but it's buried within the library.

推荐答案

你所说的你通常是由数据源提供的,在这种情况下它可以在Glassfish中配置描述如下:
https://blogs.oracle.com/JagadishPrasath/entry/connection_validation_in_glassfish_jdbc

What you state you are looking for is usually provided by the datasource, in this case it would be configurable in Glassfish as described here: https://blogs.oracle.com/JagadishPrasath/entry/connection_validation_in_glassfish_jdbc

如果您想在没有数据源的情况下这样做,例如通过将URL传递给提供者并使其具有句柄连接,那么它将特定于EclipseLink。 EclipseLink有一些选项,当它试图重新连接并重试查询时,可以配置它们,如
public void setPingSQL(String pingSQL)
public void setQueryRetryAttemptCount(int queryRetryAttemptCount)
public void setDelayBetweenConnectionAttempts int delayBetweenConnectionAttempts)
可以通过自定义程序在DatabaseLogin或DatabasePlatform类上设置的方法。

If you want to do this without a datasource, for instance by passing a URL to the provider and have it handle connections, it will be EclipseLink specific. EclipseLink does have options that can be configured when it attempts to reconnect and retry queries, such as the public void setPingSQL(String pingSQL) public void setQueryRetryAttemptCount(int queryRetryAttemptCount) public void setDelayBetweenConnectionAttempts(int delayBetweenConnectionAttempts) methods that can be set on the DatabaseLogin or DatabasePlatform classes through a customizer.

这篇关于JPA(EclipseLink)连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆