views:

104

answers:

1

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.

+1  A: 

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

Doug Clarke