如何修改 Eclipselink JPA 2.0 连接重试行为 [英] How To modify Eclipselink JPA 2.0 connection retry behavior

查看:27
本文介绍了如何修改 Eclipselink JPA 2.0 连接重试行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何修改 Eclipselink JPA 2.0 连接重试行为.当 Eclipselink 检测到连接失败时,它会自动尝试将其自身重新连接到数据库,这会导致 swing ui 冻结而没有任何响应,直到它连接到数据库.是否有任何解决方案来修改此行为即连接失败时是否可以抛出异常而不重试请帮助解决这个问题我面临着巨大的问题.

How To modify Eclipselink JPA 2.0 connection retry behavior . Eclipselink automatically tries to reconnect it self to database whenever it detects a connection failure this causes swing ui to freeze without any responses until it connects to database . Are there any solution to modify this behavior Ie is it possible to throw exception when connection fails without retrying Please help on this issue I am facing with huge problem.

我浏览了 eclipselink 源代码和谷歌,但找不到任何解决方案.

I went throe eclipselink source code and google but I could not find any solution.

推荐答案

使用 SessionCustomizer 可以禁用重新连接.

Using a SessionCustomizer you can disable the connection reconnection.

package acme;
import  org.eclipse.persistence.internal.sessions.factories.SessionCustomizer;
import org.eclipse.persistence.sessions.Session;
import org.eclipse.persistence.sessions.DatabaseLogin;

public class EmployeeSessionCustomizer implements SessionCustomizer {

    public void customize(Sesssion session) {
        DatabaseLogin login = (DatabaseLogin)session.getDatasourceLogin();
        login.setConnectionHealthValidationOnError(false);
    }
}

这个定制器可以通过一个持久化单元属性来设置

This customizer can be set through a persistence unit property

 <property name="eclipselink.session.customizer" value="acme.EmployeeSessionCustomizer"/>

这篇关于如何修改 Eclipselink JPA 2.0 连接重试行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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