[英]Auditing for Oracle with EclipseLink JPA
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: 我正在使用EclipseLink,我必须在oracle中进行审核,因此我可以在V$session
使用纯JDBC进行审核,并且可以通过这种方式在oracle中审核应用程序名称,但是在EclipseLink JPA中,我无法设置要审核的应用程序名称,我一直在尝试的方式是通过动态地设置要使用SessionCustomizer
的会话参数,但是它没有执行应做的事情...没有显示错误,但没有审核oracle中的名称...我有时间为此而苦苦挣扎,没有结果,我使用的代码是:
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 ... 我正在阅读eclipse链接http://wiki.eclipse.org/Configuring_a_Session_(ELUG) ,它是以这种方式完成的...
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. 您对如何解决此问题有任何想法吗?
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. 我建议使用SessionEventListener,以便每次从数据源创建或获取JDBC连接时都可以获取回调。
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 道格
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.