Failed to acquire data source with JPA and EclipseLink

Posted on

Question :

When I put it to persistence.xml , using a JNDI resource configured in Glassfish itself does not give an error. But when it is to get from file glassfish-resource.xml it gives the following error:


Information: [EL Info]: 2014-07-09 12: 24: 19,019 – ServerSession (1076034183) – EclipseLink,
  version: Eclipse Persistence Services – 2.5.0.v20130507-3faac2b
  [EL Severe]: ejb: 2014-07-09 12: 24: 19,038 – ServerSession (1076034183)
  Exception [EclipseLink-7060] (Eclipse Persistence Services – 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.ValidationException
  Exception Description: Can not acquire data source [jdbc / Bank].
  Internal Exception: javax.naming.NamingException: Lookup failed for ‘jdbc / Integration’ in SerialContext
  [myEnv = java.naming.factory.initial = com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state =, java.naming .factory.url.pkgs = com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: Bank not found]

Here are the files used:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-// GlassFish Application Server 3.1 Resource Definitions//EN" "">
    <jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="pool_de_conexao" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">

          <!-- Propriedades da conex√£o -->          

    <jdbc-resource enabled="true" jndi-name="jdbc/Banco" object-type="user" pool-name="pool_de_conexao"/>


<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"  xmlns_xsi="" xsi_schemaLocation="">
  <persistence-unit name="" transaction-type="RESOURCE_LOCAL">


Answer :

For some unknown reason, the file containing the JDBC Resource is not being deployed along with the application.

In this case, then adding connection properties to the persistence.xml file solves the connection problem.

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"  xmlns_xsi="" xsi_schemaLocation="">
  <persistence-unit name="" transaction-type="RESOURCE_LOCAL">
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://*******" />
        <property name="javax.persistence.jdbc.user" value="*******" />
        <property name="javax.persistence.jdbc.password" value="*******" />
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />


How is the structure of your project? is a .war , .ear or .jar ? where are you putting glassfish-resource.xml ?

I do not understand much about Glassfish, but the problem is generic:
basically your datasource file is not coming together with your application in deploy.
Check the startup log if jndi is being registered.

Resource files must be located in the META-INF folder (for .ear or .jar) or WEB-INF (for .war) for deploy to the container.

Otherwise, why are you using the transaction type as RESOURCE_LOCAL on an application server? let the server take care of the heavy lifting for you, at a glance.


If you do not resolve your issue, please update this information so we can help you better.


Leave a Reply

Your email address will not be published. Required fields are marked *