我正在使用 EclipseLink,我必须在 Oracle 中进行审核,这样我就可以使用 V$session
使用纯 JDBC 进行审核,并且我可以以这种方式审核 Oracle 中的应用程序名称,但在 EclipseLink JPA 中,我无法设置要审核的应用程序名称,我一直在尝试的方法是使用 SessionCustomizer
动态设置我想要的 session 参数,但它没有执行应该执行的操作...没有显示错误,但不审核名称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);
}
它执行合并的效果非常好,但不会审核我想要存入数据库的应用程序名称。
您知道如何解决这个问题吗?
最佳答案
我建议使用 SessionEventListener,这样每次创建 JDBC 连接或从数据源获取连接时您都可以获得回调。
public void postAcquireConnection(SessionEvent event) {
Connection conn = ((DatabaseAccessor)event.getResult()).getConnection();
您可以在使用连接之前在此处设置您需要的任何值。
道格
关于java - 使用 EclipseLink JPA 审计 Oracle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3015848/