1

我正在使用 EclipseLink,我必须在 oracle 中进行审核,因此我可以使用纯 JDBC 进行审核,V$session并且我可以通过这种方式在 oracle 中审核应用程序名称,但是在 EclipseLink JPA 中我无法设置要审核的应用程序名称,方式我一直在尝试的是通过动态设置我想要使用的会话参数,SessionCustomizer但它没有做应该做的事情......没有显示错误,但没有审核oracle中的名称......我有时间在这个问题上挣扎没有结果,我使用的代码是:

定制器类是:

package com.util; 

import org.eclipse.persistence.config.SessionCustomizer; 
import org.eclipse.persistence.sessions.Session; 

public class ProgramCustomizer implements SessionCustomizer { 
    public void customize(Session s) throws Exception { 
        //s.getDatasourceLogin().setProperty("v$session.program","Employees"); //tried with this method 
        //s.getLogin().setProperty("v$session.program","Employees"); //tried with this one as well 
    } 
} 

通过使用上面应该工作的注释行之一,没有工作......

还尝试将这些行更改为这些行:

DatabaseLogin login= (DatabaseLogin) s.getDatasourceLogin(); 
login.setProperty("v$session.program","Clients"); 

也没有工作。

我正在阅读 Eclipse 链接http://wiki.eclipse.org/Configuring_a_Session_(ELUG)并以这种方式完成...

编辑方法是:

public void edit(Employee employee) { 
    emProperties.put(PersistenceUnitProperties.SESSION_CUSTOMIZER, "com.util.ProgramCustomizer"); 
    factory = Persistence.createEntityManagerFactory("EJBLocalPU", emProperties); 
    em = factory.createEntityManager(); 
    em.merge(employee); 
} 

它很好地执行了合并,但不会将我想要的应用程序名称审核到数据库中。

您对如何解决此问题有任何想法。

4

1 回答 1

1

我建议使用 SessionEventListener 以便每次从数据源创建或获取 JDBC 连接时都可以获得回调。

public void postAcquireConnection(SessionEvent event) {
    Connection conn = ((DatabaseAccessor)event.getResult()).getConnection();

在这里,您可以在连接使用之前设置您需要的任何值。

道格

于 2010-07-29T16:40:23.570 回答