3

(scroll to end for possible bug this relates to.)

this connection pool seems correct, at least the ping is successful, but how is it actually referenced by the EJB module?

thufir@dur:~$ 
thufir@dur:~$ glassfish-4.1/glassfish/bin/asadmin
Use "exit" to exit and "help" for online help.
asadmin> 
asadmin> list-jdbc-connection-pools
CLI031: Warning: Option "target" is obsolete and will be ignored.
CLI031: Warning: Option "target" is obsolete and will be ignored.
__TimerPool
DerbyPool
SamplePool
connectionPool
legacy_on_glassfish
Command list-jdbc-connection-pools executed successfully.
asadmin> 
asadmin> ping-connection-pool legacy_on_glassfish
Command ping-connection-pool executed successfully.
asadmin> 
asadmin> list-jdbc-resources
jdbc/sample
jdbc/__TimerPool
jdbc/__default
jdbc/local
jdbc/legacy_resource
Command list-jdbc-resources executed successfully.
asadmin> 

(I wasn't sure how to output the jdbc connection propertes with asadmin)

Using the Netbeans wizard, this is the resulting persistence.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" 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">
  <persistence-unit name="EnterpriseLegacyJDBC-ejbPU" transaction-type="JTA">
    <jta-data-source>jdbc/legacy_resource</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="javax.persistence.schema-generation.database.action" value="create"/>
    </properties>
  </persistence-unit>
</persistence>

However, choosing "New Entity Classes from Database" results in:

name missing

From the Glassfish console, what is the name of the driver class for the datasource?

looking in the console, the Datasource Classname is com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource, while the Driver Classname isn't editable:

enter image description here

-------------------------------------bug report------------------------------------------

strayan@netbeans.org 2013-11-25 09:13:49 UTC

Sorry for the confusion, when you create the DataSource from the NetBean IDE like mentioned in the tutorial it works fine like you said. But when selecting a DataSource that is created outside (using GlassFish Server Admin console) of the IDE which shows in the IDE we see the error.

https://netbeans.org/bugzilla/show_bug.cgi?id=238667#c19

However, I'm not sure what's meant by a DataSource created use the GlassFish Server Admin console -- just can't find that option.

see also:

http://computingat40s.wordpress.com/how-to-setup-a-jdbc-connection-in-glassfish/

Thufir
  • 8,216
  • 28
  • 125
  • 273

6 Answers6

6

I was facing the same problem in case of PostgreSQL and performed the following steps for successful database connection with Netbean:

  1. Remove all the connection pools and data sources created by you from GlassFish using admin console
  2. Right-click the project name in NetBeans.
  3. Select New->Other->Glassfish->JDBC Connection Pool.
  4. Click Next.
  5. Give pool name.
  6. Select New Configuration using Database.
  7. Select Postgres from drop down list.
  8. In next step Enter these six parameters and their values:
    • User - postgres;
    • DatabaseName - (your DB name);
    • ServerName - localhost;
    • PortNumber - 5432;
    • Password - (password of postgre);
    • URL - jdbc:postgresql://localhost:5432/DBname
  9. Right-click the project
  10. Select New->Other->Glassfish->JDBC Resource.
  11. Select Use existing JDBC Pool.
  12. Select the pool name you have created in previous bullet.
  13. Set the name of resource
  14. Click Finish.

Now based on this resource you can create entities and whole EJB stuff without any problem.

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
5

Well, this would seem to be a bug:

omniprof@netbeans.org 2014-05-31 16:59:40 UTC

Ran into the same problem with GlassFish 4.0, NetBeans 8.0 and Java 1.8 when using a Driver. The previous comment is the solution. "add property driverClass with value com.mysql.jdbc.Driver to additional parameters of JDBC Connection Pool" When using a DataSource carefully review the long list of parameters. There are a number of items to be filled in. Will blog about them soon.

https://netbeans.org/bugzilla/show_bug.cgi?id=238667#c19

add property

where is this configuration file? How do you view it? see also:

https://askubuntu.com/questions/534320/jdbc-connection-pool-details-on-glassfish

Community
  • 1
  • 1
Thufir
  • 8,216
  • 28
  • 125
  • 273
  • I'll have to come back to this q/a, I don't think this answer is useful..or, maybe it is a bug. – Thufir Oct 16 '14 at 08:15
  • jeesh, I don't recall. I don't want to drop it -- at the very minimum there's activity on the bug, so this might be affecting others. I've kinda gone in other directions for the time being. I'll come back to this, but for now it's dormant for me. – Thufir Nov 12 '14 at 21:42
  • 1
    Found a solution - using GF 4.1 and mysql jar 5.1.34 everything works as expected! – Dror Cohen Nov 17 '14 at 09:05
  • @DrorCohen I hope this question helped you. When you have time, do post your solution as an answer, and perhaps comment on the linked bug :) – Thufir Nov 17 '14 at 09:18
  • @Thufir I solved it by copying the driver used in Glassfish to Netbeans. See my answer for more details. – GeraldScott Sep 26 '15 at 08:52
2

This worked for me:

1- Make sure that your database server is running

2- Make sure that your application server is NOT running by stoping GlassFish Server

http://netbeans-org.1045718.n5.nabble.com/The-name-of-the-driver-class-for-the-datasource-is-missing-td5725182.html

1

I found that using GF 4.1 and NB 8.0.1 (on Ubuntu 14.04 and Windows 2008 server both 64 bit) and using the mysql-connector-java-5.1.34-bin.jar file -> fixed all my problems.

Dror Cohen
  • 6,731
  • 5
  • 29
  • 32
1

I got the same error with PostgreSQL.

But it was solved by adding the url property to Glassfish pool.

In MySQL it's like jdbc:mysql://[host1][:port1]/[database]]

0

In my case, the problem was caused by a mismatch between the version of the PostgreSQL driver in Glassfish and the one in NetBeans.

I copied postgresql-9.4-1203.jdbc41.jar from my GLASSFISH_HOME/glassfish/domains/domain1/lib to NETBEANS_HOME/ide/modules/ext and deleted the older version that was already there, which solved the problem.

I hit this issue using a NetBeans plugin to generate a Primefaces CRUD application from the entity classes, following the instructions here.

I tried the solution described by @Rehan and I was able to generate the entity beans, but then the plugin was unable to detect the entities, presumably because it uses the datasource created in Glassfish.

Some other commentators had success copying the driver class to Netbeans, so I deleted the project, recreated the datasource in Glassfish and when I copied the PostgreSQL driver in Glassfish to Netbeans I saw an older version of the driver in Netbeans that I deleted, and it all worked OK.

GeraldScott
  • 481
  • 5
  • 8