• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Auditing for Oracle with EclipseLink JPA

Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 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();


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.-
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Enrique Castro
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Posts: 2658
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"xkalibur castro", please check your private messages for a javaRanch administrative matter.
Enrique Castro
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
them good ole boys were drinking whiskey and rye singin' this'll be the day that I die. Drink tiny ad.
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic