【问题标题】:Auditing for Oracle with EclipseLink JPA使用 EclipseLink JPA 审计 Oracle
【发布时间】:2023-03-14 12:26:01
【问题描述】:

我正在使用 EclipseLink,我必须在 oracle 中进行审核,因此我可以使用带有 V$session 的纯 JDBC 进行审核,并且我可以通过这种方式在 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); 
} 

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

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

【问题讨论】:

    标签: java oracle jpa eclipselink audit


    【解决方案1】:

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

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

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

    道格

    【讨论】:

      猜你喜欢
      • 2016-08-22
      • 1970-01-01
      • 2021-03-13
      • 1970-01-01
      • 2019-12-18
      • 2011-07-10
      • 2011-04-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多