You might come across this error while working with Java Persistence API (JPA) on Glassfish server. I came across this while working with both MySQL and Derby. To fix this, you have to create a new JDBC Resource and JDBC Connection Pool from Glassfish Server Administration Console.
Follow the steps below to fix the issue:
1. Login to Glassfish Server Administration Console:
After starting the Glassfish Server, you can access the Administration Console from http://localhost:4848/.
2. Create a new JDBC Connection Pool
Navigate to Resources > JDBC > JDBC Connection Pools and create a new JDBC Connection Pool.
Give the pool a name and select javax.sql.DataSource from Resource Type and select MySql from Database Driver Vendor. If you are using Derby, select Derby instead of MySql.
Click next and click Finish in Step 2.
3. Edit the newly created Connection Pool:
Once again navigate to Resources > JDBC > JDBC Connection Pools and click the name of the Connection Pool you created in Step 2.
Open the Additional Properties tab and add the following properties to Additional Properties.
(Click the image to see a large version)
Make sure to update the values with your own. The same properties are required for Derby as well.
Once you are done, save the settings.
4. Test the Connection Pool:
After saving, go back to General Tab, and click the Ping button to test the connection. If the connection is successful, you will see the “Ping Succeeded” message.
5. Create a new JDBC Resource:
Navigate to Resources > JDBC > JDBC Resources and create a new JDBC Resource.
Select the Connection Pool you created earlier from Pool Name. JNDI Name can be anything, we will use this name as a reference later.
Click Ok and you are done. No additional properties are required here.
6. Edit persistence.xml
Open NetBeans, navigate to your EJB module > Configuration Files, and open persistence.xml.
Change the value of Data Source to the JNDI Name of the JDBC Resource. In Step 5, I specified “MySQLConnection” as the value of JNDI Name of the JDBC Resource.
You should be able to run the project now. If you have any problems, leave a comment below.