2010-06-10 75 views
1

我正在使用EclipseLink,因此我可以在oracle中进行审计,以便我可以使用纯JDBC与V$session进行审计,并且我可以使用这种方式在oracle中审计应用程序名称,但是在EclipseLink JPA中我无法设置要审核的应用程序名称,我一直在尝试的方式是通过动态设置我想要使用SessionCustomizer的会话参数,但它不会执行应有的操作...没有显示错误,但不会审计名称在Oracle ......我有时间这一点,并没有结果挣扎,我使用的代码是:使用EclipseLink对Oracle进行审计JPA

的定制类是:

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

通过使用注释行以上,这是为了工作,没有工作的一个...

也试过这些线路将改变这些的:

​​

没有工作过。

我读日食链接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); 
} 

它执行合并得很好,但不审核的应用名字我想要进入数据库。

你对如何解决这个问题有任何想法。

回答

1

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

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

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

Doug