jasmine
jasmine

Reputation: 361

Entity Class from Database....Error Invalid resource _pm

I have created a database and table in MySQL through phpMyAdmin. I am trying to connect this to my project using Entity class from database. However I get the following error when I run my project:

Caused by: com.sun.appserv.connectors.internal.api.ConnectorRuntimeException:      Invalid resource : java:module/companyDB__pm

I have searched for hours and it seems lots of people have a similar problem however I have not been able to solve it following the steps provided. For example I tried to follow the steps here: http://www.nagazuka.nl/2014/03/invalid-resource-with-netbeans-8_27.html but has not helped. I have tried making changes in my glassfish-resources.xml and persistence.xml but nothing is working. Any help is appreciated please!

Upvotes: 2

Views: 757

Answers (2)

jasmine
jasmine

Reputation: 361

  1. In addition to the screenshots provided by @YCF_L, I went to the persistence.xml file, and changed the data source name to the same name as the JNDI name given in the JDBC Resource (jdbc/companyDB).

  2. Also when making the Connection Pool, I selected MySQL for the database driver vendor since I am using the PHPMyAdmin MySQL. For the additional properties when making the connection pool, the following needs to be filled: URL (jdbc:mysql://:3306/databaseName), url, Server Name, Database Name, User, Password.

  3. I was not able to make a connection to a database with no password so I needed to set one.

Upvotes: 2

Youcef LAIDANI
Youcef LAIDANI

Reputation: 59960

This error Invalid resource : java:module/companyDB__pm mean that your JNDI is not exist in your server, so to solve your problem you have to create a JNDI in your GlassFish server manually with the same name companyDB

For example :

After login to your server you will see this :

Select JDBC

Create JDBC Connection Pool

enter image description here

Fill information and press next i'm using PostgresSQL so in your case choose MySQL :

enter image description here

Fill the connection information and press finish :

enter image description here

To check if your connecton is succes of not press ping and check :

enter image description here

Now create JDBC Ressources :

enter image description here

Create a new JNDI specify the same name in your application and choose the pool that you already create it before and press finish :

enter image description here

Now you can deploy your application, hope this can help you.

Upvotes: 2

Related Questions