Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glassfish-resources.xml ignored with NetBeans 8.0.1?

I have just used NetBeans 8.0.1 and GlassFish 4.1 for 2 old projects which worked well with NetBeans 8.0 and GlassFish 4.0.

Now (with NetBeans 8.0.1) I get an error "tInvalid resource : jdbc/nameOfTheSource__pm" during the deployment of the projects.

The JDBC resource and the connection pool are defined by glassfish-resources.xml (generated by NetBeans when I defined a new entity with the option "Create Persistent Unit" and "New Data Source").

If I use directly glassfish-resources by the command add-resource of asadmin, on the server, all is working: the connection pool and the JDBC resources are created. So the problem does not come from this file.

It is as if glassfish-resources.xml were ignored during the deployment.

Did someone had the same problem (and have an explanation)?

My environment: NetBeans 8.0.1, GlassFish 4.1, Java DB 10.10.1.2 - (1495037) (from Java 8.0).

Related question : how glassfish-resources is used during the deployment? It is not included in the EAR or WAR files.

Thanks in advance for your help.

like image 662
user1643352 Avatar asked Oct 31 '22 16:10

user1643352


2 Answers

It is a bug of GlassFish: https://netbeans.org/bugzilla/show_bug.cgi?id=243034

I define my datasource in the application by @DatasourceDefinition instead of using glassfish-resources.xml but it is a workaround just for a datasource, not for other types of resources.

like image 131
user1643352 Avatar answered Nov 09 '22 08:11

user1643352


This is due to a NetBeans bug they say they had fixed but seemingly they had not. As a solution, I also ended up abandoning glassfish-resources.xml altogether and using @DataSourceDefinition annotation instead.

My configuration uses a separate DataSourceBean.java file for @DataSourceDefinition:

@Singleton
@Startup
@DataSourceDefinition(name="java:global/jdbc/myDataSource",
    className="com.microsoft.sqlserver.jdbc.SQLServerDataSource",
    url="jdbc:sqlserver://127.0.0.1:1433;databaseName=myDB",
    user="myuser",
    password="mypassword"
)
public class DataSourceBean {
}

persistence.xml looks like that:

<?xml version="1.0" encoding="UTF-8"?>
<persistence 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"
             version="2.1">
    <persistence-unit name="myUnit" transaction-type="JTA">
        <jta-data-source>java:global/jdbc/myDataSource</jta-data-source>
        <properties>
            <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
        </properties>
    </persistence-unit>
</persistence>
like image 22
Wade Avatar answered Nov 09 '22 06:11

Wade