Home » Eclipse Projects » EclipseLink » use one connectio nper user - no connection pool
| |
Re: use one connectio nper user - no connection pool [message #390519 is a reply to message #390518] |
Wed, 22 July 2009 10:51 |
Thomas Haskes Messages: 147 Registered: July 2009 |
Senior Member |
|
|
Thanks for the fast answer. How can I force the method
Persistence.createEntityManagerFactory() to create a second connection
pool? According to the EL output the persistence.xml is read only once,
and so is the creation of the entitymanager. The first time i create an
EMF i see some output and the first time I create an EntityManager I see
7 logins from the first user (which is the default connection pool i
think), The second time I do all this I get a different EMF object and
EM object, but i see no output and no more logins from the second user.
Don't know why.
tbee schrieb:
> You could consider creating EMF's each with a limited pool (one
> correction for reading, one for writing) and use a map to get to the EMF
> when you know what the user is. You have to turn off caching in that
> case, so changes between EMF are forwarded.
>
> I have a JSE/Swing fat client using EL, but there only one user logs in
> per running instance of the application, and thus I do not need multiple
> EMFs. One per application (configured for the one logged in user) suffices.
>
> Tom too
>
>
>
>
> Thomas Haskes wrote:
>> Hi all,
>>
>> I really need some help on this Problem. I'm using EL in a JavaSE
>> Environment and want to have to entitymanagers with different dbuser
>> connection so that e.g em1 uses "scott" "tiger" and em2 uses "jeff"
>> "someone" as the database user. I tried to set the user in the
>> Properties while creating the emf using
>> Persistence.createEntityManagerFactory("myPu", props)
>>
>> where the key PersistenceUnitProperties.JDBC_USER and JDBC_PASSWORD
>> are set.
>>
>> This works fine when the first emf is created but the second emf just
>> uses the same user as the first. I saw in another post that someone used
>> not the PersistenceUnitProperties as keys but
>> "javax.persistence.jdbc.user". I tried that, but this ended up in an
>> error saying "no suitable driver found".
>>
>> I tried not to set user password credentials on the emf but on the
>> entitymanager using the entitymanagerproperties but the the
>> entitymanager tries to connect to the database using the user "" which I
>> think is a bug.
>>
>> What am I missing?
>>
>> Later,
>>
>> Tom
>
|
|
| | | |
Re: use one connectio nper user - no connection pool [message #390584 is a reply to message #390583] |
Thu, 23 July 2009 06:36 |
Thomas Haskes Messages: 147 Registered: July 2009 |
Senior Member |
|
|
Oh, I see. You mean setting the user and password properties at the
EntityManager like this:
HashMap map = new HashMap();
map.put(EntityManagerProperties.JDBC_USER, "John");
map.put(EntityManagerProperties.JDBC_USER, "pass");
emf.createEntityManager(map);
If you meant that. this didn't work. Unfortunately this Results in a
login using "" as username, which I consider a bug.
If did not mean that, sorry, then I couldn't follow you. Could you
provide me with a little snippet then? Sorry if I'm puzzled. Please set
me straight.
tbee schrieb:
> No. I mean "Em1" and "Em2", each having its own user set using the
> properties parameter in Java.
>
> Are you configuring the users in the persistence.xml?
>
> Tom
>
>
> Thomas Haskes wrote:
>> Thanks, i tried that already and it works, but since we are developing
>> an application that expects to have about 2000 users, this is simply not
>> an option.
>>
>> tbee schrieb:
>>> Hm. That is unexpected; appearantly some data is stored statically. That
>>> amazes me, since all configuration is done via instance level methods.
>>>
>>> How about configuring two identical EMFs? Each EMF has a name in the
>>> persistence.xml; create two identical ones.
>>>
>>>
>>>
>>> Thomas Haskes wrote:
>>>> Thanks for the fast answer. How can I force the method
>>>> Persistence.createEntityManagerFactory() to create a second connection
>>>> pool? According to the EL output the persistence.xml is read only once,
>>>> and so is the creation of the entitymanager. The first time i create an
>>>> EMF i see some output and the first time I create an EntityManager I
>>>> see
>>>> 7 logins from the first user (which is the default connection pool i
>>>> think), The second time I do all this I get a different EMF object and
>>>> EM object, but i see no output and no more logins from the second user.
>>>> Don't know why.
>>>>
|
|
|
Re: use one connectio nper user - no connection pool [message #390585 is a reply to message #390584] |
Thu, 23 July 2009 07:35 |
Tom Eugelink Messages: 825 Registered: July 2009 |
Senior Member |
|
|
That most definitely works, because that is the way I do it. Has been running in production for a year now:
static public EntityManagerFactory createEntityManagerFactory(Class jdbcDriver, String jdbcUrl, String jdbcUsr, String jdbcPwd)
{
Map<String, Object> lOptions = new HashMap<String, Object>();
lOptions.put(PersistenceUnitProperties.JDBC_DRIVER, jdbcDriver);
lOptions.put(PersistenceUnitProperties.JDBC_URL, jdbcUrl);
lOptions.put(PersistenceUnitProperties.JDBC_USER, jdbcUsr);
lOptions.put(PersistenceUnitProperties.JDBC_PASSWORD, jdbcPwd);
lOptions.put(PersistenceUnitProperties.TARGET_DATABASE, InformixPlatform.class.getName());
lOptions.put(PersistenceUnitProperties.TARGET_SERVER, TargetServer.None);
lOptions.put(PersistenceUnitProperties.JOIN_EXISTING_TRANSAC TION, "true"); // reads and write should go through the same connection
lOptions.put(PersistenceUnitProperties.CACHE_SHARED_DEFAULT, "false"); // do not use the shared cache (otherwise refresh will not update from db)
lOptions.put(PersistenceUnitProperties.LOGGING_EXCEPTIONS, "true");
EntityManagerFactory lEntityManagerFactory = Persistence.createEntityManagerFactory("reinders", lOptions);
// done
return lEntityManagerFactory;
}
Tom
Thomas Haskes wrote:
> Oh, I see. You mean setting the user and password properties at the
> EntityManager like this:
>
> HashMap map = new HashMap();
> map.put(EntityManagerProperties.JDBC_USER, "John");
> map.put(EntityManagerProperties.JDBC_USER, "pass");
> emf.createEntityManager(map);
>
> If you meant that. this didn't work. Unfortunately this Results in a
> login using "" as username, which I consider a bug.
>
> If did not mean that, sorry, then I couldn't follow you. Could you
> provide me with a little snippet then? Sorry if I'm puzzled. Please set
> me straight.
>
> tbee schrieb:
>> No. I mean "Em1" and "Em2", each having its own user set using the
>> properties parameter in Java.
>>
>> Are you configuring the users in the persistence.xml?
>>
>> Tom
>>
|
|
|
Re: use one connectio nper user - no connection pool [message #390586 is a reply to message #390585] |
Thu, 23 July 2009 14:15 |
Thomas Haskes Messages: 147 Registered: July 2009 |
Senior Member |
|
|
Thank you so much, unfortunately this doesn't work either. I think it
worked for you because you have not a shared environment. The class
persistence just doesn't create the emf twice. I think the emf is stored
as singleton. I somehow need get it working by setting username and
password on the entitymanager. I managed to to do that, but I still end
up in an NPE while proccessing ConnectionPolicyProperties, don'nt know
what that means at all.
tbee schrieb:
> That most definitely works, because that is the way I do it. Has been
> running in production for a year now:
>
> static public EntityManagerFactory createEntityManagerFactory(Class
> jdbcDriver, String jdbcUrl, String jdbcUsr, String jdbcPwd)
> {
> Map<String, Object> lOptions = new HashMap<String, Object>();
> lOptions.put(PersistenceUnitProperties.JDBC_DRIVER, jdbcDriver);
> lOptions.put(PersistenceUnitProperties.JDBC_URL, jdbcUrl);
> lOptions.put(PersistenceUnitProperties.JDBC_USER, jdbcUsr);
> lOptions.put(PersistenceUnitProperties.JDBC_PASSWORD, jdbcPwd);
> lOptions.put(PersistenceUnitProperties.TARGET_DATABASE,
> InformixPlatform.class.getName());
> lOptions.put(PersistenceUnitProperties.TARGET_SERVER,
> TargetServer.None);
>
> lOptions.put(PersistenceUnitProperties.JOIN_EXISTING_TRANSAC TION,
> "true"); // reads and write should go through the same connection
> lOptions.put(PersistenceUnitProperties.CACHE_SHARED_DEFAULT,
> "false"); // do not use the shared cache (otherwise refresh will not
> update from db)
> lOptions.put(PersistenceUnitProperties.LOGGING_EXCEPTIONS,
> "true");
> EntityManagerFactory lEntityManagerFactory =
> Persistence.createEntityManagerFactory("reinders", lOptions);
>
> // done
> return lEntityManagerFactory;
> }
>
> Tom
>
>
>
>
> Thomas Haskes wrote:
>> Oh, I see. You mean setting the user and password properties at the
>> EntityManager like this:
>>
>> HashMap map = new HashMap();
>> map.put(EntityManagerProperties.JDBC_USER, "John");
>> map.put(EntityManagerProperties.JDBC_USER, "pass");
>> emf.createEntityManager(map);
>>
>> If you meant that. this didn't work. Unfortunately this Results in a
>> login using "" as username, which I consider a bug.
>>
>> If did not mean that, sorry, then I couldn't follow you. Could you
>> provide me with a little snippet then? Sorry if I'm puzzled. Please set
>> me straight.
>>
>> tbee schrieb:
>>> No. I mean "Em1" and "Em2", each having its own user set using the
>>> properties parameter in Java.
>>>
>>> Are you configuring the users in the persistence.xml?
>>>
>>> Tom
>>>
|
|
|
Re: use one connectio nper user - no connection pool [message #390587 is a reply to message #390586] |
Thu, 23 July 2009 15:28 |
Tom Eugelink Messages: 825 Registered: July 2009 |
Senior Member |
|
|
Yeah. Maybe the EclipseLink developers can shed a light on this. I would expect the code I pasted to return two different EMF's when different u/p are provided.
Tom
Thomas Haskes wrote:
> Thank you so much, unfortunately this doesn't work either. I think it
> worked for you because you have not a shared environment. The class
> persistence just doesn't create the emf twice. I think the emf is stored
> as singleton. I somehow need get it working by setting username and
> password on the entitymanager. I managed to to do that, but I still end
> up in an NPE while proccessing ConnectionPolicyProperties, don'nt know
> what that means at all.
>
> tbee schrieb:
>> That most definitely works, because that is the way I do it. Has been
>> running in production for a year now:
>>
>> static public EntityManagerFactory createEntityManagerFactory(Class
>> jdbcDriver, String jdbcUrl, String jdbcUsr, String jdbcPwd)
>> {
>> Map<String, Object> lOptions = new HashMap<String, Object>();
>> lOptions.put(PersistenceUnitProperties.JDBC_DRIVER, jdbcDriver);
>> lOptions.put(PersistenceUnitProperties.JDBC_URL, jdbcUrl);
>> lOptions.put(PersistenceUnitProperties.JDBC_USER, jdbcUsr);
>> lOptions.put(PersistenceUnitProperties.JDBC_PASSWORD, jdbcPwd);
>> lOptions.put(PersistenceUnitProperties.TARGET_DATABASE,
>> InformixPlatform.class.getName());
>> lOptions.put(PersistenceUnitProperties.TARGET_SERVER,
>> TargetServer.None);
>>
>> lOptions.put(PersistenceUnitProperties.JOIN_EXISTING_TRANSAC TION,
>> "true"); // reads and write should go through the same connection
>> lOptions.put(PersistenceUnitProperties.CACHE_SHARED_DEFAULT,
>> "false"); // do not use the shared cache (otherwise refresh will not
>> update from db)
>> lOptions.put(PersistenceUnitProperties.LOGGING_EXCEPTIONS,
>> "true");
>> EntityManagerFactory lEntityManagerFactory =
>> Persistence.createEntityManagerFactory("reinders", lOptions);
>>
>> // done
>> return lEntityManagerFactory;
>> }
>>
>> Tom
>>
>>
>>
>>
>> Thomas Haskes wrote:
>>> Oh, I see. You mean setting the user and password properties at the
>>> EntityManager like this:
>>>
>>> HashMap map = new HashMap();
>>> map.put(EntityManagerProperties.JDBC_USER, "John");
>>> map.put(EntityManagerProperties.JDBC_USER, "pass");
>>> emf.createEntityManager(map);
>>>
>>> If you meant that. this didn't work. Unfortunately this Results in a
>>> login using "" as username, which I consider a bug.
>>>
>>> If did not mean that, sorry, then I couldn't follow you. Could you
>>> provide me with a little snippet then? Sorry if I'm puzzled. Please set
>>> me straight.
>>>
>>> tbee schrieb:
>>>> No. I mean "Em1" and "Em2", each having its own user set using the
>>>> properties parameter in Java.
>>>>
>>>> Are you configuring the users in the persistence.xml?
>>>>
>>>> Tom
>>>>
|
|
| |
Goto Forum:
Current Time: Wed Feb 05 19:10:43 GMT 2025
Powered by FUDForum. Page generated in 0.04497 seconds
|