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 8281977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:12:53+00:00 2026-06-08T10:12:53+00:00

I’ve been working on a web application, deployed on Tomcat 7, which use EclipseLink

  • 0

I’ve been working on a web application, deployed on Tomcat 7, which use EclipseLink JPA to handle the persistence layer.

Everything works fine in a test environment but we’re having serious issues in the production environment due to a firewall cutting killing inactive connections. Basically if a connection is inactive for a while a firewall the sits between the Tomcat server and the DB server kill it, with the result of leaving “stale” connections in the pool.

The next time that connection is used the code never returns, until it gets a “Connection timed out” SQLException (full ex.getMessage() below).

EL Fine]: 2012-07-13
18:24:39.479–ServerSession(309463268)–Connection(69352859)–Thread(Thread[http-bio-8080-exec-5,5,main])–
MY QUERY REPLACED TO POST IT TO SO [EL Config]: 2012-07-13
18:40:10.229–ServerSession(309463268)–Connection(69352859)–Thread(Thread[http-bio-8080-exec-5,5,main])–disconnect
[EL Info]: 2012-07-13
18:40:10.23–UnitOfWork(1062365884)–Thread(Thread[http-bio-8080-exec-5,5,main])–Communication
failure detected when attempting to perform read query outside of a
transaction. Attempting to retry query. Error was: Exception
[EclipseLink-4002] (Eclipse Persistence Services –
2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException Internal
Exception: java.sql.SQLException: Eccezione IO: Connection timed out

I already tried several configuration in the persistence.xml, but since I have no access to the firewall configuration I had no luck with these methods. I also tried to use setCheckConnections()

ConnectionPool cp = ((JpaEntityManager)em).getServerSession().getDefaultConnectionPool();
        cp.setCheckConnections();
        cp.releaseConnection(cp.acquireConnection());

I managed to solve the issue in a test script using testOnBorrow, testWhileIdle and other features that are avalaible from DBCP Apache Commons. I’d like to know how to override the EclipseLink internal connection pool to use a custom connection pool so that I can provide an already configured pool, based on DBCP rather than just configuring the internal one using persistence.xml.

I know I should provide a SessionCustomizer, I’m uncertain which one is the correct pattern to use. Basically I would like to preserve the performance of DBCP in a JPA-like way.

I’m deploying on Tomcat 7, I know that if I switch to GF I won’t have this problem, but for a matter of consistency with other webapp on the same server I’d prefere to stay on Tomcat.

  • 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-06-08T10:12:54+00:00Added an answer on June 8, 2026 at 10:12 am

    What you want is definitely possible, but you might be hitting the limits of the “do it yourself” approach.

    This is one of the more difficult things to explain, but there are effectively two ways to configure your EntityManagerFactory. The “do it yourself” approach and the “container” approach.

    When you call Persistence.createEntityManagerFactory it eventually delegates to this method of the PersistenceProvider interface implemented by EclipseLink:

    EntityManagerFactory    createEntityManagerFactory(String emName, Map map) 
    

    The deal here is EclipseLink will then take it upon itself to do all the work, including its own connection creation and handling. This is the “do it yourself” approach. I don’t know EclipseLink well enough to know if there is a way to feed it connections using this approach. After two days on Stackoverflow it doesn’t seem like anyone else has that info either.

    So here is why this “works in GF”. When you let the container create the EntityManagerFactory for you by having it injected or looking it up, the container uses a different method on the PersistenceProvider interface implemented by EclipseLink:

    EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map map) 
    

    The long and short of it is that this PersistenceUnitInfo is an interface that the container implements and has these two very key methods on it:

    public DataSource getJtaDataSource();
    public DataSource getNonJtaDataSource();
    

    With this mode EclipseLink will not try to do its own connection handling and will simply call these methods to get the DataSource from the container. This is really what you need.

    There are two possible approaches you could take to solving this:

    • You could attempt to instantiate the EclipseLink PersistenceProvider implementation yourself and call the createContainerEntityManagerFactory method passing in your own implementation of the PersistenceUnitInfo interface and feed the DBCP configured DataSource instances into EclipseLink that way. You would need to parse the persistence.xml file yourself and feed that data in through the PersistenceUnitInfo. As well EclipseLink might also expect a TransactionManager, in which case you’ll be stuck unless you hunt down a TransactionManager you can add to Tomcat.

    • You could use the Java EE 6 certified version of Tomcat, TomEE. DataSources are configured in the tomee.xml, created using DBCP with full support for all the options you need, and passed to the PersistenceProvider using the described createContainerEntityManagerFactory call. You then get the EntityManagerFactory injected via @PersistenceUnit or look it up.

    If you do attempt to use TomEE, make sure your persistence.xml is updated to explicitly set transaction-type="RESOURCE_LOCAL" because the default is JTA. Even though it’s non-compliant to use JTA with the Persistence.createEntityManagerFactory approach, there aren’t any persistence providers that will complain and let you know you’re doing something wrong, they treat it as RESOURCE_LOCAL ignoring the schema. So when you go to port your app to an actual certified server, it blows up.

    Another note on TomEE is that in the current release, you’ll have to put your EclipseLink libs in the <tomcat>/lib/ directory. This is fixed in trunk, just not released yet.

    I’m not sure how useful these slides will be without the explanation that goes along with them, but the second part of this presentation is a deep dive into how container-managed EntityManager’s work, specifically with regards to connection handling and transactions. You can ignore the transaction part as you aren’t using them and already have an in production you’re not likely to dramatically change, but it might be interesting for future development.

    Best of luck!

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

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.