Search code examples
jpaeclipselink

How to initialize EclipseLink connection


Sorry if my question is quite simple, but I really couldn't find an answer googling. I have this project with JPA 2.0 (EclipseLink), it's working fine but I want to ask if there's a way to initialize the database connection?

Actually it begins whenever the user try to access any module that requires any query, which is quite annoying because the connection can take some seconds and the app froze for a second when it's connecting. I can make any random query on main method for "turn it on", but it's an unnecesary query and not the solution I want to use.

Thanks beforehand!


Solution

  • The problem will be that the deployment process is lazy. This prevents the cost of initializing and connecting to unused/unneeded persistence units, but it means everything with a persistence unit is processed the very first time it is accessed.

    This can be configured on a persistence unit by using the "eclipselink.deploy-on-startup" property: http://www.eclipse.org/eclipselink/documentation/2.4/jpa/extensions/p_deploy_on_startup.htm