Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1015211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:22:01+00:00 2026-05-16T10:22:01+00:00

We have an application that needs to access a database that is owned by

  • 0

We have an application that needs to access a database that is owned by a different team.
That database has security inside the database (triggers, table permissions, etc) and so we need to establish a connection to the database using the same username/password that connected to our EJB.

We’re running on JBoss 5.1. Standard Java EE solutions are preferred, but JBoss specific answers will do.

At the moment our solution is


  • Create a datasource in JBoss with no user-id password

  • Require the client to pass their username/password into the EJB (the EJB is a stateful session bean (SFSB), and remembers the username/password)

  • The session bean creates a new connection using DataSource.getConnection(String, String)

  • The connection is “created” from the datasource at the start of each request (The datasource implementation might reuse an existing connection)

The main problem we have is connection pooling.
The JBoss connection pool doesn’t manage separate pools for each username – they’re all thrown into 1 big pool, and the username is checked after the object is retrieved from the pool (inside InternalManagedConnectionPool).
If the usernames don’t match, then the connection is removed from the pool & destroyed.
This means that as soon as we have 2 users, there’s a 50% chance that any connection that is put into the pool will be destroyed when it is next accessed. And as we increase the number of users, those odds get a lot worse.

We can’t simply create 1 connection in the SFSB and retain it because JBoss is too smart for us, and it detects that we’ve left a connection open and automatically returns it to the pool for us, so the next request to the SFSB will fail with a “not associated” connection.

It would also be nice if we could simply get JBoss to create a connection as “the currently logged in user”, but the solution we have is bearable.

My googling has failed to find any recommended patterns for doing this sort of thing. Everyone seems to assume that you want your datasource to use a single user for all connections (which is nice when it’s possible, but I can’t do that in this case)

The only solutions I can some up with are


  1. Don’t use a container provided datasource. Put the JDBC URL into a configuration value somewhere and create connections myself (possibly with the help of spring)

  2. Bind a different Datasource implementation (possibly a custom one) into JNDI

Has anyone got any better solutions? Or pointers to recommended practices in this area?

(The database is Sybase ASE 15, but I doubt that makes any difference to the solution)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:22:01+00:00Added an answer on May 16, 2026 at 10:22 am

    A bit more reading of the documentation has led me to what appears to be the solution.
    Adding
    <application-managed-security/>
    into my datasource file seems to have fixed the problem of pooling the connections.

    I’m not sure how I missed that the first time around.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've more than one activity (inside the same Application) that needs to have access
Scenario: I have a console application that needs to access a network share with
I have an application that needs to determine whether a user has made a
My application database has a Groups table that separates users into logical roles and
I have an application that needs to connect to a SQL database, and execute
I'm writing an internal business application that needs to access a number of different
I have a web application that needs a database back-end. My back-end is really
I have a Silverlight application that needs to retrieve some data from my database.
I have a JavaEE application that needs to access a file in order to
I have a web application that will need to access code behind methods as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.