This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 271348 - Cannot retrieve datasources
Summary: Cannot retrieve datasources
Status: NEW
Alias: None
Product: serverplugins
Classification: Unclassified
Component: GlassFish (show other bugs)
Version: 8.2
Hardware: PC Linux
: P2 normal (vote)
Assignee: Petr Hejl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-22 17:31 UTC by thangalin
Modified: 2017-08-22 17:35 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
JDBC pool and resources (81.02 KB, image/png)
2017-08-22 17:31 UTC, thangalin
Details
Shows NetBeans and Payara being out of sync. (95.83 KB, image/png)
2017-08-22 17:35 UTC, thangalin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description thangalin 2017-08-22 17:31:29 UTC
Created attachment 164988 [details]
JDBC pool and resources

Replicate

1. Install NetBeans 8.2 into /opt/netbeans/.
2. Install Payara 41 into /opt/payara/.
3. Install PostgreSQL 9.3.13
4. Create a new domain in Payara.
5. Change ownership of domain to same user running NetBeans.
6. Create a new JDBC connection within NetBeans.
7. Import JDBC connection information (glassfish-resources.xml) into Payara.

Verification

* Can query database tables in NetBeans
* Can manually deploy the application.
* JDBC connectivity established in server.

Problem

JDBC resources are unavailable to Payara Server through NetBeans. This causes the feature of "Create entities from database" to fail silently after a prolonged period of time. Similarly, deploying the application takes a long time, but eventually succeeds.

However, deploying the application manually via the Payara admin console is nearly instantaneous.

At the end of the expanded steps, below, the expected result is that the JDBC resource for the database is available.

The actual result is that NetBeans hangs for up to five minutes before returning without any JDBC resources at all.

--

Expanded steps to replicate follow.

# Installation

These instructions assume a non-Windows operating system.

1. Install JDK into `/opt/jdk`
1. Install NetBeans into `/opt/netbeans`
    * Do not install an application server (uncheck GlassFish).
    * Use the JDK from `/opt/jdk`.
1. Install Maven into `/opt/maven`.

# Configuration

This section describes how to configure the development environment.

## Environment Variables

Configure the PATH variable (e.g., by editing `.bashrc`) as follows:

```
JAVA_HOME=/opt/jdk
NETBEANS_HOME=/opt/netbeans
MAVEN_HOME=/opt/maven

PATH=$PATH:$JAVA_HOME/bin
PATH=$PATH:$MAVEN_HOME/bin
PATH=$PATH:$NETBEANS_HOME/bin
```

## Create Database Role

Once the database software is running, connect using `psql` and run:

```
CREATE ROLE fitness;
ALTER ROLE fitness WITH SUPERUSER;
ALTER ROLE fitness CREATEDB;
```

The role is configured.

## Integrated Development Environment

This section describes how to set up the Integrated Development Environment (IDE).

Start the NetBeans IDE.

### Maven

Configure Maven as follows:

1. Open Tools.
1. Click **Java**.
1. Set **Maven Home** to `/opt/maven`.
1. Click **OK**.

Maven is configured.

### JDBC Driver

Copy the JDBC driver to the JDK lib directory. For example:

```
sudo cp postgresql-42.1.4.jar /opt/jdk/lib/
```

The JDBC driver is installed.

### Database Service

Configure and verify the database connection as follows:

1. Return to the IDE.
1. Click the **Services** tab.
1. Right-click **Databases**.
1. Select **New Connection**.
1. Click **Add**.
1. Browse to and select `postgresql-42.1.4.jar`.
1. Click **OK**.
1. Click **Next**.
1. Set **User Name** to: `fitness`
1. Set **Password**.
1. Click **Test Connection**.
1. Correct any mistakes.
1. Check **Remember password**.
1. Click **Finish**.
1. Rename to database service to `Fitness`.

The database service is configured.

### Create Database Schema

Create the database schema as follows:

1. Expand **Databases → Fitness**.
1. Right-click **Fitness**.
1. Click **Execute Command**.
1. Click **File → Open File**.
1. Browse to and select `fitness.sql`.
1. Click **Open**.
1. Set **Connection** to: `Fitness`.
1. Press `Ctrl+Shift+E` to run the file.

The database schema is created.

Optionally, reduce the privileges to `fitness`:

```
ALTER ROLE fitness WITH NOSUPERUSER;
```

### Payara

Install Payara into `/opt/payara` then configure Payara as follows:

1. Create a domain as `root`:
    * export JAVA_HOME=/opt/jdk && PATH=$PATH:$JAVA_HOME/bin
    * /opt/payara/bin/asadmin create-domain fitness
1. Press `Enter` to accept the default user name (admin) and empty password.
1. Start the domain:
    * /opt/payara/bin/asadmin start-domain fitness
1. Browse to: http://localhost:4848/
1. Expand **Configurations → server-config → Network Config → Network Listeners → admin-listener**.
1. Change **Address** from `0.0.0.0` to `127.0.0.1`.
1. Click **Save**.
1. Change the permissions of the `fitness` directory to the user running the IDE.
    * chown -R username.username /opt/payara/glassfish/domains/fitness
1. Stop and restart the domain.
    * /opt/payara/bin/asadmin stop-domain fitness
    * /opt/payara/bin/asadmin start-domain fitness

Payara is configured.

### Payara Plugin

Install the Payara plugin as follows:

1. Click **Tools → Plugins**.
1. Click **Available Plugins**.
1. Search for **Payara**.
1. Check **EE Common**, **Common**, **Java EE**, and **Tooling**.
1. Click **Install**.
1. Continue through the installation wizard.
1. Restart the IDE when prompted.

The plugin is installed.

### Payara-IDE Integration

Associate Payara with the IDE as follows:

1. Click **Tools → Servers**.
1. Click **Add Server**.
1. Select **Payara Server**.
1. Set **Name** to: `Payara`
1. Click **Next**.
1. Set **Installation Location** to: `/opt/payara`
    * If a warning appears (admin-listener is disabled or no enabled http-listener), ensure `/opt/payara/glassfish/domains/fitness` has write access.
1. Check **I have read and accept...**
1. Click **Next**.
1. Set **Domain** to `fitness` (should be selected by default).
1. Set **User Name** to: `admin`
1. Leave **Password** empty.
1. Click Finish.
1. Uncheck **Start Registered Derby Server**.
1. Click **Close** to close the **Servers** dialog.

Payara is integrated with the IDE.

# Create Project

This is one-time task is required to create the application.

1. Start NetBeans.
1. Type `Ctrl+Shift+N` to create a new project.
1. Set **Categories** to: `Maven`
1. Set **Projects** to: `Web Application`
1. Click **Next**.
1. Set **Project Name** to: `fitness`
1. Set **Project Location** as appropriate.
1. Set **Group Id** to: `ca.domainname`
1. Click **Next**.
1. Click **Finish**.

# Create JDBC Resource

Create a JDBC resource and connection pool as follows:

1. Right-click the project name.
1. Click **New → Other**.
1. Set **Categories** to: `GlassFish`
1. Set **File Types** to: `JDBC Resource`
1. Click **Next**.
1. Select **Create New JDBC Connection Pool**.
1. Set **JNDI Name** to: `jdbc/fitnessDS`
1. Set **Description** to: `Fitness data source.`
1. Click **Next**.
1. Click **Next**, again.
1. Set **JDBC Connection Pool Name** to: `FitnessPool`
1. Click **Next**.
1. Set **Datasource Classname** to: `org.postgresql.ds.PGConnectionPoolDataSource`
1. Set **Resource Type** to: `javax.sql.ConnectionPoolDataSource`
1. Set **Description** to: `Fitness data source connection pool.`
1. Click **Finish**.

The JDBC Connection Pool is created.

# Create Web Server Connection Pool 

Configure a JDBC connection pool for Payara as follows:

1. Copy the JDBC driver into Payara's GlassFish lib directory.
    * cp /opt/jdk/lib/postgresql-42.1.4.jar /opt/payara/glassfish/lib/
1. Restart the domain.
1. Visit http://localhost:4848/
1. Click **Resources**.
1. Click **Add Resources**.
1. Click **Browse**.
1. Browse to and select `fitness/src/main/webapp/WEB-INF/glassfish-resources.xml`
1. Click **OK**.

Test the pool as follows:

1. Expand **Resources → JDBC → JDBC Connection Pools**.
1. Click **FitnessPool**.
1. Click **Ping**.

If the ping did not succeed, correct the errors before continuing. The log file can be found at:

```
/opt/payara/glassfish/domains/fitness/logs
```

# Remove Extraneous Pools

Remove extra connection pools as follows:

1. Expand **Resources → JDBC → JDBC Connection Pools**.
1. Check **Derby Pool**.
1. Check **__TimerPool**.
1. Click **Delete**.
1. Click **OK** to confirm.

The pools are removed.

# Generate Entities

Generate entities from tables as follows:

1. Open the **Projects** tab.
1. Right-click the `fitness` project.
1. Select **New → Entity Classes from Database**
Comment 2 thangalin 2017-08-22 17:35:17 UTC
Created attachment 164989 [details]
Shows NetBeans and Payara being out of sync.