Skip to content

How to set application name with JPA (EclipseLink)?

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


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




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 {
    public void customize(Session s) throws Exception {
        s.getDatasourceLogin().setProperty("v$session.program", "Customers");

emProperties.put(PersistenceUnitProperties.SESSION_CUSTOMIZER, "ProgramCustomizer"); 
User contributions licensed under: CC BY-SA
7 People found this is helpful