Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » use one connectio nper user - no connection pool
use one connectio nper user - no connection pool [message #390517] Wed, 22 July 2009 09:07 Go to next message
Thomas Haskes is currently offline Thomas HaskesFriend
Messages: 147
Registered: July 2009
Senior Member
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 #390518 is a reply to message #390517] Wed, 22 July 2009 10:12 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 817
Registered: July 2009
Senior Member
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 #390519 is a reply to message #390518] Wed, 22 July 2009 10:51 Go to previous messageGo to next message
Thomas Haskes is currently offline Thomas HaskesFriend
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 #390581 is a reply to message #390519] Wed, 22 July 2009 12:43 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 817
Registered: July 2009
Senior Member
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 #390582 is a reply to message #390581] Wed, 22 July 2009 12:56 Go to previous messageGo to next message
Thomas Haskes is currently offline Thomas HaskesFriend
Messages: 147
Registered: July 2009
Senior Member
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 #390583 is a reply to message #390582] Wed, 22 July 2009 13:01 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 817
Registered: July 2009
Senior Member
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 #390584 is a reply to message #390583] Thu, 23 July 2009 06:36 Go to previous messageGo to next message
Thomas Haskes is currently offline Thomas HaskesFriend
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 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 817
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 Go to previous messageGo to next message
Thomas Haskes is currently offline Thomas HaskesFriend
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 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 817
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
>>>>
Re: use one connectio nper user - no connection pool [message #390588 is a reply to message #390587] Fri, 24 July 2009 06:17 Go to previous message
Thomas Haskes is currently offline Thomas HaskesFriend
Messages: 147
Registered: July 2009
Senior Member
That's the strange part - it does, but it won't read the persistence XML
an properties again, so I end up with a different emf object, which is
logged in as the same user it logged the first time.

Does anyone know if there is way to provide an em with a connection I
set up myself? Maybe i can get an exclusive connection per user to work
this way...

tbee schrieb:
> 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
Previous Topic:createquery
Next Topic:Performaces
Goto Forum:
  


Current Time: Fri Apr 19 10:20:31 GMT 2024

Powered by FUDForum. Page generated in 0.03093 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top