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

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

问题描述

如何修改Eclipselink JPA 2.0连接重试行为。
当它检测到连接失败时,Eclipselink会自动尝试重新连接到数据库,这会导致swing ui在没有任何响应的情况下冻结,直到它连接到数据库。
有任何解决方案来修改这个行为
Ie是可能的,当连接失败时抛出异常,而不重试
请帮助这个问题
我面临巨大的问题。 p>

我去了eclipselink源代码和google,但我找不到任何解决方案。

解决方案

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

  
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);
}
}

此定制器可以通过持久性单元属性

 < property name =eclipselink.session.customizervalue =acme.EmployeeSessionCustomizer/& 


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.

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

解决方案

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天全站免登陆