问题描述
大家好,我将JPA与EclipseLink和oracle作为数据库一起使用,我需要设置属性 jdbc4的v $ session ,它允许为应用程序设置标识名称以进行审核,但是我已经不太幸运地进行设置。...我一直在按照此页面中的示例尝试通过entitiyManager:它没有显示任何错误,但根本没有设置应用程序名称...当我在oracle中看到审核时,它的名称没有被审核我通过代码 Customers设置,但使用OS_program_name = JDBC Thin Client,这意味着代码中的属性设置不正确,并且我不知道问题出在哪里,我使用的代码如下:
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....
谢谢。-
推荐答案
v $ session.program
是JDBC连接属性,但是 Persistence.createEntityManagerFactory
获取持久性单元属性。没有直接的方法可以将任意JDBC属性传递给实体管理器。
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.
但是,在EclipseLink中,您可以使用 SessionCustomizer
:
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");
这篇关于在使用JPA设置应用程序名称时需要帮助(EclipseLink)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!