这是JBoss的standalone.xml
JBoss数据源故障转移在单个事务中如何处理失败?
<connection-url>
jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=xx.1xx.119.1xx)(PORT=1521))(LOAD_BALANCE=on)(FAILOVER=on))(CONNECT_DATA=(SERVICE_NAME=XE)))
</connection-url>
我的连接细节我想处理故障转移的一个角落情况后persist()
在通话过程中得到EntityManager
对象,连接丢失。故障切换选项不会切换到同一事务中的下一个数据库,它会在下一个事务中切换到活动连接。我尝试了这样的事情:(Catch Exception并获取更新的bean对象)
public EntityManager getEntityManager() {
try {
entityManager = getEntityManagerDao(Constant.JNDI_NFVD_ASSURANCE_ENTITY_MANAGER);
} catch (NamingException e) {
LOGGER.severe("Data could not be persisted.");
throw new PersistenceException();
}
return entityManager.getEntityManager();
}
/**
* Inserts record in database. In case multiple connections/databases exist, one more attempt will be made to
* insert record.
*
* @param entry
*/
public void persist(Object entry) {
try {
getEntityManager().persist(entry);
} catch (PersistenceException pe) {
LOGGER.info("Could not persist data. Trying new DB connection.");
getEntityManager().persist(entry);
}
}
private static Object getJNDIObject(String path) throws NamingException {
Object jndiObject = null;
InitialContext initialContext = new InitialContext();
jndiObject = initialContext.lookup(path);
return jndiObject;
}
private static AssuranceEntityManager getEntityManagerDao(String path) throws NamingException {
return (AssuranceEntityManager) getJNDIObject(path);
}
但是这个也没有帮助。在捕获异常之后,使用JNDI查找获取新bean不会包含更新的新连接,并引发异常。这导致该交易的数据丢失。
请建议如何处理“连接失去后获取EntityManager和持续之前”的角落案例。