javaoraclejpapersistence.xmlhibernate-5.x

Setting vsession.program in java app using hibernate 5 and c3po connection pool


I'm trying to set the session program name from my java app. I'm using an entity manager passing the connection credentials from user input.

I need to be able to set the program name in the oracle session when connected. Right now it only appears as "JDBC Thin Client". I've attempted setting the entity manager properties in java and tried numerous variations in my persistence.xml.

Java snippet

            props.put( hibernate.connection.url, "jdbc:oracle:thin:@localhost:1521:XE");
            props.put( "hibernate.connection.username", username );
            props.put( "hibernate.connection.password", password );
            props.put( "v$session.program", "MYPROGRAM" );

            emf = Persistence.createEntityManagerFactory( "MYDB", props );

            em = emf.createEntityManager();

Persistence.xml

<?xml version="1.0" encoding="UTF-8"?><persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="MYDB">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
        <!-- Hibernate properties -->
        <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
        <property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
        <property name="hibernate.show_sql" value="false"/>
        <property name="hibernate.cache.use_second_level_cache" value="false"/>
        <!-- Connection Pool -->
        <property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />
        <property name="hibernate.c3p0.max_size" value="20" />
        <property name="hibernate.c3p0.min_size" value="5" />
        <property name="hibernate.c3p0.acquire_increment" value="5" />
        <property name="hibernate.c3p0.idle_test_period" value="300" />
        <property name="hibernate.c3p0.max_statements" value="0" />
        <property name="hibernate.c3p0.timeout" value="100" />
        <property name="connectionProperties" value="v$session.program:MYPROGRAM" />
    </properties>
</persistence-unit>

I'm limited in what techonologies to use, so I cannot use EclipseLink as suggested here

Is there any other way to set this either in the java app or in the persistence.xml file?


Solution

  • The properties hibernate.connection.X are the connection properties passed to JDBC. The property that you are using is also a JDBC one, so you should try to set as below. It worked for me.

    code

    <property name="hibernate.connection.v$session.program" value="MYPROGRAM" />