1

hello everybody i am using JPA with EclipseLink and oracle as DB and i need to set the property v$session of jdbc4 it allows to set an identification name to the application for auditing purposes but i had no lucky setting it up....i have been trying through entitiyManager following the example in this page: http://wiki.eclipse.org/Configuring_a_EclipseLink_JPA_Application_(ELUG) it does not show any error but does not set the application name at all... when i see the audit in oracle it is not being audited with the name i set by code "Customers" but with OS_program_name=JDBC Thin Client it means that the property in the code is not being set properly and i have no idea where the issue is, the code i am using is the following :

    emProperties.put("v$session.program","Customers");
    factory=Persistence.createEntityManagerFactory("clients",emProperties);
    em=factory.createEntityManager(emProperties);        
    em.merge(clients);

does anybody know how to do it or any idea....

thanks.-

MWiesner
  • 8,868
  • 11
  • 36
  • 70
Alvaro Castro
  • 199
  • 1
  • 4
  • 22

2 Answers2

1

v$session.program is a JDBC connection property, but Persistence.createEntityManagerFactory gets persistence unit properties. There is no direct way to pass arbitrary JDBC property into entity manager.

However, in EclipseLink you can use SessionCustomizer:

public class ProgramCustomizer extends SessionCustomizer {
    @Override
    public void customize(Session s) throws Exception {
        s.getDatasourceLogin().setProperty("v$session.program", "Customers");
        super.customize(s);
    }
}

-

emProperties.put(PersistenceUnitProperties.SESSION_CUSTOMIZER, "ProgramCustomizer"); 
axtavt
  • 239,438
  • 41
  • 511
  • 482
0

You can achive that without SessionCustomizer in persistence.xml:

<property name="eclipselink.jdbc.property.v$session.program" value="Customers" />

FYI: https://www.eclipse.org/eclipselink/documentation/2.7/jpa/extensions/persistenceproperties_ref.htm#CIHHJHHD

Gmugra
  • 468
  • 7
  • 10