Data source failed with JPA and Eclipselink

Asked

Viewed 551 times

3

When I put for the persistence.xml use a JNDI Resource configured in Glassfish itself. But when it is to take from the file glassfish-resource.xml 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 Information: [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: Cannot Acquire data source [jdbc/Banco]. Internal Exception: javax.naming.Namingexception: Lookup failed for 'jdbc/Integracao' in Serialcontext [myEnv= java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.Factory.url.pkgs=com.sun.Enterprise.naming} [Root Exception is javax.naming.Namenotfoundexception: Bank not found]

Follow the used files:

glassfish-Resource.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
    <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-connection-pool>
    <jdbc-resource enabled="true" jndi-name="jdbc/Banco" object-type="user" pool-name="pool_de_conexao"/>

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="br.com.app-1.0-SNAPSHOTPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <non-jta-data-source>jdbc/Banco</non-jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
  </persistence-unit>
</persistence>

2 answers

1

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

I don’t know much about Glassfish, but the problem is generic: basically your datasource file is not coming together with your application in the deploy. Check the startup log to see if jndi is being registered.

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

Other than that, because you’re using the transaction type as RESOURCE_LOCAL on an application server ? let the server take care of the heavy work for you, a look here HERE.

If you don’t solve your problem, update this information so we can help you better.

  • For some reason, which I don’t know, the glassfish-Resource.xml file is not going along with the app. And about JTA instead of RESOURCE_LOCAL is a good option, but it doesn’t work with the solution I found.

0


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

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

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="br.com.app-1.0-SNAPSHOTPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
      <properties>
        <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" />
    </properties>
  </persistence-unit>
</persistence>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.