With a persistent.xml like:
<properties>
<property name="toplink.jdbc.driver" value="oracle.jdbc.OracleDriver" />
<property name="toplink.jdbc.url" value="jdbc:oracle:thin:@192.168.56.22:1521:sit" />
<property name="toplink.jdbc.user" value="user1" />
<property name="toplink.jdbc.password" value="user1" />
</properties>
And the following code:
static {
emf = Persistence.createEntityManagerFactory("CUCCWarPU");
threadLocal = new ThreadLocal<EntityManager>();
logger = Logger.getLogger("CUCCWarPU");
logger.setLevel(Level.ALL);
}
public static EntityManager getEntityManager() {
EntityManager manager = threadLocal.get();
Properties jpaMap = new Properties();
jpaMap.put(TopLinkProperties.JDBC_USER, "user2");
jpaMap.put(TopLinkProperties.JDBC_PASSWORD, "user2");
if (manager == null || !manager.isOpen()) {
manager = emf.createEntityManager(jpaMap);
manager.threadLocal.set(manager);
}
return manager;
}
When manager==null or manager is closed, the new EntityManager instantiated
by emf.createEntityManager(jpaMap); is supposed to override the properties parameters of the persistent unit. Isn't it?
But by the way, this new manager has still the same user1/user1 properties.
I know EntityManagerFactory can be instantiated passing a Map that YES overwrite persistent.xml parameters. But what happens with then new EntityManager I want to create? Why emf.createEntityManager(jpaMap) has a parameter for a map of properties but does not do anything? Is it unimplemented??
I also know EntityManagerFactory is implemented by the container, and there is another doubt. I'm proving it with Tomcat 6. Could be this one reason? Would it work on a glassfish?
Thanks a lot for your future answers, since I'm in the middle of an important project, whose requeriments ask for dynamic user/rol changes (like proxy user).
thanks again!!!
[Message sent by forum member 'fonsito' (fonsito)]
http://forums.java.net/jive/thread.jspa?messageID=267279