Java, JPA, Glassfish, Invalid resource : jdbc/__default__pm

62,938

Solution 1

If you have only created a MySQL connection pool, you must also create a JDBC resource. This can be created from the context menu above the one you used to create the connection pool.

Example Glassfish jdbc resource setup

In my Glassfish, my JDBC resource, jdbc/__default is using the connection pool mysql_lemon.

Solution 2

the __nontx and __pm are extensions to the pool. documentation: https://docs.oracle.com/cd/E19798-01/821-1752/beamr/index.html (somewhere else http://docs.oracle.com/cd/E26576_01/doc.312/e24930/jdbc.htm#GSDVG00185 and http://docs.oracle.com/cd/E26576_01/doc.312/e24930/transaction-service.htm#GSDVG00512)

first __pm

from https://docs.oracle.com/cd/E19798-01/821-1752/gavro/index.html

Allowing Non-Component Callers

You can allow non-Java-EE components, such as servlet filters, lifecycle modules, and third party persistence managers, to use this JDBC connection pool. The returned connection is automatically enlisted with the transaction context obtained from the transaction manager. Standard Java EE components can also use such pools. Connections obtained by non-component callers are not automatically closed at the end of a transaction by the container. They must be explicitly closed by the caller.

You can enable non-component callers in the following ways:

Check the Allow Non Component Callers box on the Edit Connection Pool Advanced Attributes page in the Administration Console. The default is false. For more information, click the Help button in the Administration Console.

Specify the ----allownoncomponentcallers option in the asadmin create-jdbc-connection-pool command. For more information, see the Oracle GlassFish Server 3.0.1 Reference Manual.

Specify the allow-non-component-callers option in the asadmin set command. For example:

asadmin set domain1.resources.jdbc-connection-pool.DerbyPool.allow-non-component-callers=true

For more information, see the Oracle GlassFish Server 3.0.1 Reference Manual.

Create a JDBC resource with a __pm suffix.

and __nontx

from https://docs.oracle.com/cd/E19798-01/821-1752/beamu/index.html

Using Non-Transactional Connections

You can specify a non-transactional database connection in any of these ways:

Check the Non-Transactional Connections box on the New JDBC Connection Pool or Edit Connection Pool page in the Administration Console. The default is unchecked. For more information, click the Help button in the Administration Console.

Specify the ----nontransactionalconnections option in the asadmin create-jdbc-connection-pool command. For more information, see the Oracle GlassFish Server 3.0.1 Reference Manual.

Specify the non-transactional-connections option in the asadmin set command. For example:

asadmin set domain1.resources.jdbc-connection-pool.DerbyPool.non-transactional-connections=true

For more information, see the Oracle GlassFish Server 3.0.1 Reference Manual.

Use the DataSource implementation in the GlassFish Server, which provides a getNonTxConnection method. This method retrieves a JDBC connection that is not in the scope of any transaction. There are two variants.

public java.sql.Connection getNonTxConnection() throws java.sql.SQLException

public java.sql.Connection getNonTxConnection(String user, String password) throws java.sql.SQLException

Create a resource with the JNDI name ending in __nontx. This forces all connections looked up using this resource to be non transactional.

Solution 3

(The same post of mine but with proper account now):

When configuring persistence with your setup, you only set the JNDI name for the JDBC pool in persistence.xml. Optional, you may set the target database name.

<persistence-unit name="foo" transaction-type="JTA">
    <jta-data-source>jdbc/mysql</jta-data-source>
    <!--optional-->
    <property name="eclipselink.target-database" value="MySQL4"/>
</persistence-unit>

I also encourage to change the 'drop-and-create-table' to 'create-tables', so that you don't loose data, and this should be be providing EclipseLink's properties in following way:

<property name="eclipselink.ddl-generation" value="create-tables"/>

and also handy

<property name="eclipselink.ddl-generation.output-mode" value="both"/>

that will create schema and sql scripts.

For more information visit: http://wiki.eclipse.org/EclipseLink/Examples/JPA/DDL or http://docs.oracle.com/cd/E19798-01/821-1752/gbwmj/index.html

Solution 4

I had the same problem.

The solution (for anybody that still have this issue):

  1. if you are using the NetBeans IDE 8.1 with Glassfish 4.1.1, I advise you to change it to Glassfish 4.1

  2. Go to the left panel in NetBeans.

Click on services > server > glassfish then right-click (in Glassfish server) and choose view domain admin console, a web page should show up.

Go to the left and choose resources > JDBC and JDBC connection pool.

Add a new connection pool by clicking on new, type the name of your pool.

Next, choose the javax.sql.ConnectionPoolDataSource and the datadriver (in my case is MySQL) and click next.

After that, you should enter all the needed information for your database.

  1. Go back to Resources > JDBC. This time, JDBC Resources create a new JDBC resources (for me, I named it jdbc/test). Don't forget to link it with the connection pool you already created.

  2. In NetBeans go to your ejb project and modify the persistence.xml file. Change the datasource to the database resource (in my case jdbc/test) and save all.

That should work.

Solution 5

I had the same problem when I run/deploy an app on a server created by netbeans instalattion wizard.

To solve I downloaded the last glassfish version from official site and went to: Netbeans > "Service's Tab" > "Servers" > "Add Server...".

Remember to change your project configurations to use the new glassfish server instance.

Share:
62,938
Victor Mezrin
Author by

Victor Mezrin

Python, JavaScript, C++, PHP, Java, C#

Updated on July 03, 2020

Comments

  • Victor Mezrin
    Victor Mezrin almost 4 years

    I use Glassfish 3.1.2.2 (build 5), JPA, EclipseLink, MySQL

    I created MySQL pool via Glassfish admin panel. Ping to MySQL from GF admin panel is ok.

    I created app with persistence.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
    <persistence-unit name="myUnit">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/myDBName"/>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="javax.persistence.jdbc.user" value="root"/>
            <property name="javax.persistence.jdbc.password" value="myPass"/>
            <property name="javax.persistence.ddl-generation" value="drop-and-create-tables"/>
        </properties>
    </persistence-unit>
    

    I tried to deploy it and got the error:

    Invalid resource : jdbc/__default__pm
    
    [#|2012-11-16T02:20:59.480+0400|SEVERE|glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=43;_ThreadName=Thread-2;|Invalid resource : jdbc/__default__pm
    java.lang.RuntimeException: Invalid resource : jdbc/__default__pm
    

    Stacktrace in GF log is huge. Started by

    at com.sun.enterprise.connectors.ConnectorRuntime.lookupDataSourceInDAS(ConnectorRuntime.java:540)
    at com.sun.enterprise.connectors.ConnectorRuntime.lookupPMResource(ConnectorRuntime.java:469)
    at org.glassfish.persistence.common.PersistenceHelper.lookupPMResource(PersistenceHelper.java:63)
    at org.glassfish.persistence.jpa.ProviderContainerContractInfoBase.lookupDataSource(ProviderContainerContractInfoBase.java:71)
    ....
    

    Does anyone have ideas what happened and what to do?

  • Bernhard
    Bernhard over 8 years
    but, from where comes the *__pm <-- ??
  • Bernhard
    Bernhard over 8 years
    why should i create the EntityManager by myself (and not using Annotation)? from where did you get that code?
  • test30
    test30 over 8 years
    If it works for you then you should use annotations, but if you are forced to use some buggy version or something, then hardcoding it might help
  • Kevin
    Kevin about 6 years
    __pm is a suffix used to allow broader access to the JDBC resource. See @Bernhard's answer
  • Luis Manrique
    Luis Manrique over 5 years
    The key is change the jta-data-source in persistence.xml file to connect with the resource that was be created