Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Eclipselink without connection pool
Eclipselink without connection pool [message #390589] Fri, 24 July 2009 06:48 Go to next message
Thomas Haskes is currently offline Thomas HaskesFriend
Messages: 147
Registered: July 2009
Senior Member
Hi all

I have the following scenario. I have a website where multiple users
connect to a database using EL. I need every user that logs in to the
website to have his own connection to the database (the users that log
in each have a database account, too). So I don't need to use connection
pooling at all. What I need is that every user gets an entitymanager
that has its own exclusive connection to the database. How an I set this
up with EL?
Re: Eclipselink without connection pool [message #390597 is a reply to message #390589] Mon, 27 July 2009 15:27 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You can do this using the
"eclipselink.jdbc.exclusive-connection.mode"="Always" persistence unit
property, and pass the user/password properties to the
EntityManagerFactory.createEntityManager() call.

You will probably also want to set your connection pool size to 1 or 0.
If you have some shared data accessible with a common user, you can set
the exclusive mode to "Isolated" and only mark the non-shared objects as
isolated (shared=false).

See,
http://www.eclipse.org/eclipselink/api/1.1.1/org/eclipse/per sistence/config/PersistenceUnitProperties.html#EXCLUSIVE_CON NECTION_MODE

---
James


James : Wiki : Book : Blog : Twitter
Re: Eclipselink without connection pool [message #390606 is a reply to message #390597] Wed, 29 July 2009 11:43 Go to previous messageGo to next message
Thomas Haskes is currently offline Thomas HaskesFriend
Messages: 147
Registered: July 2009
Senior Member
Thank you, but unfortunately this doesn't work for me either, when I do
this, I get a "No suitable Driver found" error. I'm using el in an OSGI
environment and have set the PERSISTENCEUNITPROPERTIES.CLASSLOADER
property. Without setting the user name in the emProperties (means using
the standard user which is defined on the factoryproperties) it works.

Any idea whay that happens?

As there is no property for setting the classloader at the
entitymanager, I really don't have a clue why this is happening.

James schrieb:
> You can do this using the
> "eclipselink.jdbc.exclusive-connection.mode"="Always" persistence unit
> property, and pass the user/password properties to the
> EntityManagerFactory.createEntityManager() call.
>
> You will probably also want to set your connection pool size to 1 or 0.
> If you have some shared data accessible with a common user, you can set
> the exclusive mode to "Isolated" and only mark the non-shared objects as
> isolated (shared=false).
>
> See,
> http://www.eclipse.org/eclipselink/api/1.1.1/org/eclipse/per sistence/config/PersistenceUnitProperties.html#EXCLUSIVE_CON NECTION_MODE
>
>
> ---
> James
>
Re: Eclipselink without connection pool [message #390607 is a reply to message #390606] Wed, 29 July 2009 12:55 Go to previous messageGo to next message
Thomas Haskes is currently offline Thomas HaskesFriend
Messages: 147
Registered: July 2009
Senior Member
>> You will probably also want to set your connection pool size to 1 or 0.

Besides, how do I reduce the size of the connection pool to 0? I tried
using SessionCustomizer this way:

public void customize(Session session) {
ConnectionPool conpool =
((ServerSession)session).getDefaultConnectionPool();
conpool.setName("default");
conpool.setMinNumberOfConnections(0);
conpool.setMaxNumberOfConnections(0);
((ServerSession)session).addConnectionPool(conpool);
}

This there are still 7 connections opened when the first entitymanager
is created.

Later,

Tom
Re: Eclipselink without connection pool [message #390608 is a reply to message #390607] Wed, 29 July 2009 13:32 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Set the min to 0, not the max.

There is both a read and write pool (in 2.0 you can configure a single
pool).

"eclipselink.jdbc.read-connections.min"="0"
"eclipselink.jdbc.write-connections.min"="0"

In code you need to set the default and read connection pools min.

Not sure on the OSGI issue, perhaps someone else knowledgeable on OSGI can
answer this.


James : Wiki : Book : Blog : Twitter
Re: Eclipselink without connection pool [message #405802 is a reply to message #390608] Thu, 30 July 2009 06:18 Go to previous messageGo to next message
Thomas Haskes is currently offline Thomas HaskesFriend
Messages: 147
Registered: July 2009
Senior Member
Thanks, that worked, I solved the OSGi Problem, too, I must have messed
up something.

But now there is the next strange problem comming along, so I hope I may
bother you again with that.

I now want to give the database user a certain role by setting it after
the creation of the entitymanager like this.

em.getTransaction.begin();
em.createNativeQuery(BEGIN DBMS_SESSION.SET_ROLE('userrole' IDENTIFIED
BY somepassword); END;).executeUpdate();
em.getTransaction.commit();

As there is always an exclusive connection used, I assumed this should
work. The odd thing is that it does in all following transactions that
are ended with commit();

The first transaction that is ended with a call to rollback(), causes
that the role is lost. At that time the entitymanager cannot see any of
the tables anymore to which the role grants access.

Why is that only happening when I do rollback, and not on commit?

Am I missing something?

James schrieb:
> Set the min to 0, not the max.
>
> There is both a read and write pool (in 2.0 you can configure a single
> pool).
>
> "eclipselink.jdbc.read-connections.min"="0"
> "eclipselink.jdbc.write-connections.min"="0"
>
> In code you need to set the default and read connection pools min.
>
> Not sure on the OSGI issue, perhaps someone else knowledgeable on OSGI
> can answer this.
>
>
Re: Eclipselink without connection pool [message #413741 is a reply to message #405802] Thu, 30 July 2009 09:30 Go to previous message
Thomas Haskes is currently offline Thomas HaskesFriend
Messages: 147
Registered: July 2009
Senior Member
Some more infromation:

I just figured out that setting the role after a rollback again doesnt
help, somehow the role is not associated with the user again, although
setting the role does not cause an error.

Thomas Haskes schrieb:
> Thanks, that worked, I solved the OSGi Problem, too, I must have messed
> up something.
>
> But now there is the next strange problem comming along, so I hope I may
> bother you again with that.
>
> I now want to give the database user a certain role by setting it after
> the creation of the entitymanager like this.
>
> em.getTransaction.begin();
> em.createNativeQuery(BEGIN DBMS_SESSION.SET_ROLE('userrole' IDENTIFIED
> BY somepassword); END;).executeUpdate();
> em.getTransaction.commit();
>
> As there is always an exclusive connection used, I assumed this should
> work. The odd thing is that it does in all following transactions that
> are ended with commit();
>
> The first transaction that is ended with a call to rollback(), causes
> that the role is lost. At that time the entitymanager cannot see any of
> the tables anymore to which the role grants access.
>
> Why is that only happening when I do rollback, and not on commit?
>
> Am I missing something?
>
> James schrieb:
>> Set the min to 0, not the max.
>>
>> There is both a read and write pool (in 2.0 you can configure a single
>> pool).
>>
>> "eclipselink.jdbc.read-connections.min"="0"
>> "eclipselink.jdbc.write-connections.min"="0"
>>
>> In code you need to set the default and read connection pools min.
>>
>> Not sure on the OSGI issue, perhaps someone else knowledgeable on OSGI
>> can answer this.
>>
>>
Previous Topic:Negative Ids
Next Topic:Changes in mutable objects not detected
Goto Forum:
  


Current Time: Fri Apr 19 20:45:40 GMT 2024

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

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

Back to the top