使用 EclipseLink JPA 审计 Oracle

发布于 2024-09-04 17:51:55 字数 1559 浏览 2 评论 0原文

我正在使用 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); 
} 

它执行合并非常好,但不审核我想要存入数据库的应用程序名称。

您对如何解决这个问题有任何想法吗?

I am using EclipseLink and i have to audit in oracle so I can audit using pure JDBC with the V$session and i can audit the application name in oracle in this way but here in EclipseLink JPA I cannot set the application name to be audited, the way in which I have been trying is by setting dynamically the session param I want using the SessionCustomizer but it does not do what is supposed to do... No error is shown but does not audit the name in oracle... I have time struggling with this and no result, the code I am using is:

The customizer class is:

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

By using one of the commented lines above which are supposed to work, did not work...

Also tried changing those lines into these ones:

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

Did not work too.

I was reading the eclipse link http://wiki.eclipse.org/Configuring_a_Session_(ELUG) and it is done in this way ...

The method to edit is:

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

It performs the merge very well but does not audit the application name I want into the database.

Do you have any idea on how to solve this issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

驱逐舰岛风号 2024-09-11 17:51:55

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

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

您可以在使用连接之前在此处设置您需要的任何值。

道格

I would suggest using a SessionEventListener so you can get a callback each time a JDBC connection is created or acquired from a data source.

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

Here you can set whatever values you need on the connection prior to its use.

Doug

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文