This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Auditing for Oracle with EclipseLink JPA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Auditing for Oracle with EclipseLink JPA" Watch "Auditing for Oracle with EclipseLink JPA" New topic

Auditing for Oracle with EclipseLink JPA

Enrique Castro

Joined: Jun 01, 2010
Posts: 7
Hello everybody i am using EclipseLink and have to audit in oracle i can audit using pure JDBC with the V$session and getting the application name in oracle 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 dinamically 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, usign the following code:

the customizer class is:

package com.util;

import org.eclipse.persistence.config.SessionCustomizer;
import org.eclipse.persistence.sessions.Session;

* @author xkalibur
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 instead these ones:

DatabaseLogin login= (DatabaseLogin) s.getDatasourceLogin();

did not work too.

i was reading the eclipse link 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();


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

thanks in advance.-
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
Setting the property on the login, provided it is before you have connected, will have the property passed to JDBC.

How are you setting the property in JDBC, are you just passing it as a property when you connect?

How have you configured JPA, are you using JDBC, or using a DataSource, perhaps include your persistence.xml. Normally the customizer would be in your persistence.xml.
Ensure you customizer is being called.

Note that if you have already connected your EntityManagerFactory, then customizing will not have any affect. I would guess that this is your problem.

Do you want to set the property one for the entire persistence unit, or do you want to change it for each EntityManager? If it is per EntityManager, then you may need to use EclipseLink's session events, or EntityManager login properties.

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Enrique Castro

Joined: Jun 01, 2010
Posts: 7
Hey thanks for your info i checked and consider all the points that you mentioned, and was trying in all the ways, but i have not had lucky,..

these are the project features:

netbeans 6.5.1
EclipseLink 2.0.1
Oracle 10g
jdbc14 as JDBC Driver
Using DataSource "Connection Pool"

firstly i need to have others applications with different properties and values , in this case the application name
should be set per entitymanager, so at the beginning i did not have any property in the persistence unit but i tried setting the v$session.program
directly into the entity manager like this:

but did not work no error but no works, then i realized something i am using EclipseLink 2.0.1 all the info i have found on the internet is
accessing into the package eclipselink.session.customizer but when i access the library i do no have that structure instead of that i have:

eclipse.persistence.config.SessionCustomizer i mention this because i want to be sure that all is ok...

so tried with :

same story

after that, tried setting the application name applying EclipseLink's session events i did it in this way:

but did not set the name

the code above persists ok but does not audit the name i set.

also tried setting the property directly into the entitymanager properties:

same issue...
i do not know if i am missing something , set something incorrect.
you gave me many clues...
and was trying so maybe i am doing something wrong, but do not know what, have googled a lot trying to find an example using
the parameter i need "v$session.program" with EclipseLink but it seems that there are no examples exactly about this parameter, so maybe can
help me to find the way.

Really appreciate the support.-

James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
You are using a third party DataSource connection pool. This means that EclipseLink has no control over creating the connection, so cannot pass JDBC properties to connect.

You either need to configure your JDBC properties in your DataSource, or modify the connection after its creation.

To get the JDBC connection from the EntityManager, in JPA 2.0 you can use unwrap(java.sql.Connection.class).
Or you can execute SQL if you can set your context on the database through SQL.


You could also use SessionEvents, to modify the JDBC connection. EclipseLink exposes two events, postAcquireConnection() and postAcquireExclusiveConnection(), which can be used to access the JDBC connection.

Jan Cumps

Joined: Dec 20, 2006
Posts: 2565

"xkalibur castro", please check your private messages for a javaRanch administrative matter.

OCUP UML fundamental and ITIL foundation
Enrique Castro

Joined: Jun 01, 2010
Posts: 7
Hey thanks for the support you gave me James Sutherland, all the tips were useful for me, really appreciate it.

i was struggling so hard trying to pass the application name as parameter but finally i Can do it, and it was using SessionCustomizer
firstly i tried setting the property v$session.program into the session properties but it does not work in that way :
the final solution was using a method which returns a DataSource this method gets the ConnectionPool DataSource and then
casts it into OracleDataSource which is able to manage the specific property of the Vendor "v$session.program" then is returned as DataSource
to be get by the Environment.
Here is the final code, maybe is useful for somebody:

Anton Nedbailo

Joined: Dec 03, 2014
Posts: 1
Enrique Castro wrote:
Here is the final code, maybe is useful for somebody:

Interesting solution. But the only one thing is not clear for me: where or who call the "getConnectionPool" method???

Let me offer other solution for the issue:

In my project it works.
I agree. Here's the link:
subject: Auditing for Oracle with EclipseLink JPA
It's not a secret anymore!