2010-05-24 38 views
1

大家好我是使用JPA與EclipseLink和oracle作爲數據庫,我需要設置屬性v $ session of jdbc4它允許爲應用程序設置標識名稱爲審計目的,但我沒有幸運設置它....我一直試圖通過entitiyManager下面的例子在這個頁面上:http://wiki.eclipse.org/Configuring_a_EclipseLink_JPA_Application_(ELUG)它不顯示任何錯誤,但沒有設置應用程序名稱...當我看到在oracle中進行審計時,它沒有使用我通過代碼「Customers」設置的名稱進行審計,但是使用OS_program_name = JDBC Thin Client時,這意味着代碼中的屬性沒有正確設置,我不知道問題出在哪裏,我正在使用的代碼如下:需要使用JPA設置應用程序名稱的幫助(EclipseLink)

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

沒有任何人知道如何做到這一點或任何想法....

thanks.-

回答

0

v$session.program是一個JDBC連接屬性,但Persistence.createEntityManagerFactory得到持久性單元的屬性。沒有直接的方法可以將任意JDBC屬性傳遞到實體管理器中。

然而,在你的EclipseLink可以使用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"); 
相關問題