Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [glassfish-dev] How to use Glassfish with MySQL or any database instead of Apache Derby

Em 2024-04-27 14:31, Ondro Mihályi via glassfish-dev escreveu:
Hi, Victor,

Hi Ondro!

Do you deploy the application to the DAS or to another server
instance? It looks like you deploy to an instance, because the error
you shared with us contains "Please see server.log for more details".
This is logged on the side, which triggers the deployment, while the
actual error happens on a remote server or instance. Usually, you
would get this from the asadmin deploy command, the real error is then
printed in the DAS server.log. But it seems you got this in the DAS
server.log, then I assume DAS tried to deploy on a remote instance,
logger the error with "Please see server.log for more details", while
the real error is in the server.log of the instance it tried to deploy
the application on.


I figure that this error is because this output at derby.log located in glassfish7/glassfish/databases, which returned me mostly derby content:

Sun Apr 28 11:48:36 BRT 2024 : Apache Derby Network Server - 10.15.2.0 - (1873585) started and ready to accept connections on port 1527

And when I type sudo ./asadmin start-database:

```
Starting database in Network Server mode on host 0.0.0.0 and port 1527.
--------- Derby Network Server Information --------
Version: CSS10150/10.15.2.0 - (1873585) Build: 1873585 DRDA Product Id: CSS10150
-- listing properties --
derby.drda.timeSlice=0
derby.drda.portNumber=1527
derby.drda.minThreads=0
derby.drda.sslMode=off
derby.drda.traceAll=false
derby.drda.keepAlive=true
derby.drda.maxThreads=0
derby.drda.logConnections=false
derby.drda.startNetworkServer=false
derby.drda.host=0.0.0.0
derby.drda.traceDirectory=/home/victor/Downloads/web-7.0.13/gla...
------------------ Java Information ------------------
Java Version:    21.0.2
Java Vendor:     Oracle Corporation
Java home:       /usr/lib/jvm/jdk-21-oracle-x64
Java classpath: /home/.../web-7.0.13/glassfish7/glassfish/lib/asadmin/cli-optional.jar:/home/.../web-7.0.13/glassfish7/javadb/lib/derby.jar:/home/.../web-7.0.13/glassfish7/javadb/lib/derbyshared.jar:/home/.../web-7.0.13/glassfish7/javadb/lib/derbytools.jar:/home/.../web-7.0.13/glassfish7/javadb/lib/derbynet.jar:/home/.../web-7.0.13/glassfish7/javadb/lib/derbyclient.jar
OS name:         Linux
OS architecture: amd64
OS version:      6.6.10-76060610-generic
Java user name:  root
Java user home:  /root
Java user dir:   /home/.../web-7.0.13/glassfish7/bin
java.specification.name: Java Platform API Specification
java.specification.version: 21
java.runtime.version: 21.0.2+13-LTS-58
--------- Derby Information --------
[/home/.../web-7.0.13/glassfish7/javadb/lib/derby.jar] 10.15.2.0 - (1873585) [/home/.../web-7.0.13/glassfish7/javadb/lib/derbytools.jar] 10.15.2.0 - (1873585) [/home/.../web-7.0.13/glassfish7/javadb/lib/derbynet.jar] 10.15.2.0 - (1873585) [/home/.../web-7.0.13/glassfish7/javadb/lib/derbyclient.jar] 10.15.2.0 - (1873585) [/home/.../web-7.0.13/glassfish7/javadb/lib/derbyshared.jar] 10.15.2.0 - (1873585)
------------------------------------------------------
----------------- Locale Information -----------------
Current Locale :  [English/United States [en_US]]
Found support for locale: [cs]
	 version: 10.15.2.0 - (1873585)
Found support for locale: [de_DE]
	 version: 10.15.2.0 - (1873585)
Found support for locale: [es]
	 version: 10.15.2.0 - (1873585)
Found support for locale: [fr]
	 version: 10.15.2.0 - (1873585)
Found support for locale: [hu]
	 version: 10.15.2.0 - (1873585)
Found support for locale: [it]
	 version: 10.15.2.0 - (1873585)
Found support for locale: [ja_JP]
	 version: 10.15.2.0 - (1873585)
Found support for locale: [ko_KR]
	 version: 10.15.2.0 - (1873585)
Found support for locale: [pl]
	 version: 10.15.2.0 - (1873585)
Found support for locale: [pt_BR]
	 version: 10.15.2.0 - (1873585)
Found support for locale: [ru]
	 version: 10.15.2.0 - (1873585)
Found support for locale: [zh_CN]
	 version: 10.15.2.0 - (1873585)
Found support for locale: [zh_TW]
	 version: 10.15.2.0 - (1873585)
------------------------------------------------------
------------------------------------------------------

Starting database in the background.
Log redirected to /home/.../web-7.0.13/glassfish7/glassfish/databases/derby.log.
Command start-database executed successfully.
```

I figure that the deployment is happening in DAS, this part I don't know yet I am new to Glassfish.

In server.log now typing ```sudo ./asadmin deploy <path_to_.war_file>``` I got:

```
[2024-04-29T04:37:33.397683-03:00] [GF 7.0.13] [INFO] [NCLS-REST-00001] [jakarta.enterprise.admin.rest] [tid: _ThreadID=87 _ThreadName=admin-listener(1)] [levelValue: 800] [[
  Listening to REST requests at context: /command/domain.]]

[2024-04-29T04:37:34.099374-03:00] [GF 7.0.13] [INFO] [NCLS-SECURITY-01002] [jakarta.enterprise.system.core.security] [tid: _ThreadID=87 _ThreadName=admin-listener(1)] [levelValue: 800] [[
  Java security manager is disabled.]]

[2024-04-29T04:37:34.102487-03:00] [GF 7.0.13] [INFO] [NCLS-SECURITY-01010] [jakarta.enterprise.system.core.security] [tid: _ThreadID=87 _ThreadName=admin-listener(1)] [levelValue: 800] [[
  Entering Security Startup Service.]]

[2024-04-29T04:37:34.106046-03:00] [GF 7.0.13] [INFO] [NCLS-SECURITY-01143] [jakarta.enterprise.system.core.security] [tid: _ThreadID=87 _ThreadName=admin-listener(1)] [levelValue: 800] [[ Loading policy provider org.glassfish.exousia.modules.locked.SimplePolicyProvider.]]

[2024-04-29T04:37:34.118943-03:00] [GF 7.0.13] [INFO] [NCLS-SECURITY-01011] [jakarta.enterprise.system.core.security] [tid: _ThreadID=87 _ThreadName=admin-listener(1)] [levelValue: 800] [[
  Security Service(s) started successfully.]]

[2024-04-29T04:37:34.231208-03:00] [GF 7.0.13] [INFO] [AS-WEB-GLUE-00198] [jakarta.enterprise.web] [tid: _ThreadID=87 _ThreadName=admin-listener(1)] [levelValue: 800] [[
  Created HTTP listener http-listener-1 on host/port 0.0.0.0:8080]]

[2024-04-29T04:37:34.232795-03:00] [GF 7.0.13] [INFO] [AS-WEB-GLUE-00198] [jakarta.enterprise.web] [tid: _ThreadID=87 _ThreadName=admin-listener(1)] [levelValue: 800] [[
  Created HTTP listener http-listener-2 on host/port 0.0.0.0:8181]]

[2024-04-29T04:37:34.233523-03:00] [GF 7.0.13] [INFO] [AS-WEB-GLUE-00198] [jakarta.enterprise.web] [tid: _ThreadID=87 _ThreadName=admin-listener(1)] [levelValue: 800] [[
  Created HTTP listener admin-listener on host/port 0.0.0.0:4848]]

[2024-04-29T04:37:34.241256-03:00] [GF 7.0.13] [INFO] [AS-WEB-GLUE-00200] [jakarta.enterprise.web] [tid: _ThreadID=87 _ThreadName=admin-listener(1)] [levelValue: 800] [[
  Created virtual server server]]

[2024-04-29T04:37:34.241965-03:00] [GF 7.0.13] [INFO] [AS-WEB-GLUE-00200] [jakarta.enterprise.web] [tid: _ThreadID=87 _ThreadName=admin-listener(1)] [levelValue: 800] [[
  Created virtual server __asadmin]]

[2024-04-29T04:37:34.320620-03:00] [GF 7.0.13] [INFO] [AS-WEB-CORE-00306] [jakarta.enterprise.web.core] [tid: _ThreadID=87 _ThreadName=admin-listener(1)] [levelValue: 800] [[
  Setting JAAS app name glassfish-web]]

[2024-04-29T04:37:34.321131-03:00] [GF 7.0.13] [INFO] [AS-WEB-GLUE-00201] [jakarta.enterprise.web] [tid: _ThreadID=87 _ThreadName=admin-listener(1)] [levelValue: 800] [[
  Virtual server server loaded default web module ]]

[2024-04-29T04:37:34.601601-03:00] [GF 7.0.13] [SEVERE] [] [jakarta.enterprise.system.core] [tid: _ThreadID=87 _ThreadName=admin-listener(1)] [levelValue: 1000] [[
  Exception while deploying the app [challenge2]]]

[2024-04-29T04:37:34.601857-03:00] [GF 7.0.13] [SEVERE] [NCLS-CORE-00026] [jakarta.enterprise.system.core] [tid: _ThreadID=87 _ThreadName=admin-listener(1)] [levelValue: 1000] [[
  Exception during lifecycle processing
org.glassfish.deployment.common.DeploymentException: JNDI lookup failed for the resource: Name: MySqlUnit, Lookup: java:comp/env/jdbc, Type: javax.sql.DataSource -- Lookup failed for java:comp/env/jdbc in SerialContext[myEnv={java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}] at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:836) at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:257) at java.naming/javax.naming.InitialContext.lookup(InitialContext.java:409) at java.naming/javax.naming.InitialContext.lookup(InitialContext.java:409) at java.naming/javax.naming.InitialContext.doLookup(InitialContext.java:282) at com.sun.enterprise.deployment.util.ResourceValidator.validateJNDIRefs(ResourceValidator.java:882) at com.sun.enterprise.deployment.util.ResourceValidator.validateResources(ResourceValidator.java:748) at com.sun.enterprise.deployment.util.ResourceValidator.event(ResourceValidator.java:173)
	at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:107)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:456) at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:257) at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:471) at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:570) at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:566) at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
	at java.base/javax.security.auth.Subject.doAs(Subject.java:453)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:565) at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:596) at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:588) at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
	at java.base/javax.security.auth.Subject.doAs(Subject.java:453)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:587) at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1478) at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1847) at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1723) at org.glassfish.admin.rest.resources.admin.CommandResource.executeCommand(CommandResource.java:359) at org.glassfish.admin.rest.resources.admin.CommandResource.execCommandSimpInMultOut(CommandResource.java:202) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:146) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:189) at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:176) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:93) at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:478) at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:400) at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:81) at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:261)
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265) at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:240) at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:697) at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:367) at org.glassfish.admin.rest.adapter.JerseyContainerCommandService$3.service(JerseyContainerCommandService.java:150) at org.glassfish.admin.rest.adapter.RestAdapter.service(RestAdapter.java:156) at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:425) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:144) at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:174) at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:153) at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:196) at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:88) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:246) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:178) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:118) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:96) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:51) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:510) at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:82) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:83) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:101) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:535) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:515)
	at java.base/java.lang.Thread.run(Thread.java:1583)
]]

[2024-04-29T04:37:34.602700-03:00] [GF 7.0.13] [INFO] [] [org.glassfish.web.loader.WebappClassLoader] [tid: _ThreadID=87 _ThreadName=admin-listener(1)] [levelValue: 800] [[
  close(), this:
org.glassfish.web.loader.WebappClassLoader@5c49c37e[name=unknown], urls=[
file:/home/.../web-7.0.13/glassfish7/glassfish/domains/domain1/applications/challenge2/WEB-INF/classes/
file:/home/.../web-7.0.13/glassfish7/glassfish/domains/domain1/generated/ejb/challenge2/
][delegate=true, context=unknown, status=RUNNING, antiJARLocking=false, securityManager=false, packageDefinitionSecurityEnabled=false, repositories=RepositoryManager[WEB-INF/classes/], notFound.size=33, pathTimestamps.size=6, resourceEntryCache.size=6]]]

[2024-04-29T04:37:34.613961-03:00] [GF 7.0.13] [INFO] [] [org.glassfish.web.loader.WebappClassLoader] [tid: _ThreadID=87 _ThreadName=admin-listener(1)] [levelValue: 800] [[
  close(), this:
org.glassfish.web.loader.WebappClassLoader@756dcebf[name=unknown], urls=[
file:/home/.../web-7.0.13/glassfish7/glassfish/domains/domain1/applications/challenge2/WEB-INF/classes/
file:/home/.../web-7.0.13/glassfish7/glassfish/domains/domain1/generated/ejb/challenge2/
][delegate=true, context=unknown, status=RUNNING, antiJARLocking=false, securityManager=false, packageDefinitionSecurityEnabled=false, repositories=RepositoryManager[WEB-INF/classes/], notFound.size=0, pathTimestamps.size=0, resourceEntryCache.size=0]]]

[2024-04-29T04:37:34.616448-03:00] [GF 7.0.13] [SEVERE] [] [jakarta.enterprise.system.core] [tid: _ThreadID=87 _ThreadName=admin-listener(1)] [levelValue: 1000] [[ Exception while deploying the app [challenge2] : JNDI lookup failed for the resource: Name: MySqlUnit, Lookup: java:comp/env/jdbc, Type: javax.sql.DataSource -- Lookup failed for java:comp/env/jdbc in SerialContext[myEnv={java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}]]]
```

The only bad thing is because I don't know if is possible to debug the code block where I am getting this issue!


If you want to deploy the application on an instance, the datasource
must also be available on the instance. If you created the datasource
using the Admin Console, it would automatically add the new JDBC
resource to all instances. However, if you followed Hiroki's guide
with asadmin commands, the datasource is only available on DAS.


I have followed the Hiroki's guide before

If you want to make it available on an instance named, for example,
instance1, you need to run this command too:

asadmin create-resource-ref --target instance1 jdbc/mysql


I am gonna try now this command above!

If you have a cluster of instances, use cluster name instead of
instance1.


Where could I check it?


Thank you,

Victor

Ondro

On Sat, Apr 27, 2024 at 11:35 AM Scott Marlow via glassfish-dev
<glassfish-dev@xxxxxxxxxxx> wrote:

Why is the data source not bound to jndi and why isn't a proper
error logged when the data source has trouble deploying?  Sounds
like someone needs to explain or dig into the code to improve.  I
have helped a lot to run TCK tests against glass fish and problems
like this should be fixed by those with the itch to fix when they
happen.

Maybe ask how one would try to find and improve the code responsible
for data source deployment.

Just my two dollars of thoughts on this.  Sorry about the spell
checker on my phone changing technical terms to be spelled wrong :)

Scott

On Fri, Apr 26, 2024, 10:42 AM Victor Gimenez via glassfish-dev
<glassfish-dev@xxxxxxxxxxx> wrote:

Em 2024-04-26 10:29, Victor Gimenez via glassfish-dev escreveu:
Em 2024-04-26 01:15, Hiroki Sawamura (Fujitsu) escreveu:
Hi,

Hi! Thanks again for the reply.


I did another test to verify taking all the <persistence-unit
name="MySqlUnit"> XML block on persistence.xml and I received
another
message:

```
Error occurred during deployment: Exception while preparing the
app :
Could not resolve a persistence unit corresponding to the
persistence-context-ref-name
[dukes.greeting.GreetingRepository/em] in
the scope of the module called [challenge2]. Please verify your
application.. Please see server.log for more details.
```

[challenge2] : JNDI lookup failed for the resource: Name:
MySqlUnit,
Lookup: jdbc/mysql, Type: javax.sql.DataSource -- Lookup
failed for
jdbc/mysql in

Hm, it seems that for JPA the resource type should be
javax.sql.DataSource.
so, try changing the JDBC connection pool resource type to
"javax.sql.DataSource" and the data source class name to
"com.mysql.cj.jdbc.MysqlDataSource".



With javax.sql.DataSource as JDBC connection pool and
com.mysql.cj.jdbc.MysqlDataSource I am facing the same thing:

```An error has occurred Error occurred during deployment:
Exception
while deploying the app [challenge2] : JNDI lookup failed for
the
resource: Name: MySqlUnit, Lookup: jdbc/mysql, Type:
javax.sql.DataSource -- Lookup failed for jdbc/mysql in



SerialContext[myEnv={java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl,

java.naming.factory.url.pkgs=com.sun.enterprise.naming}]. Please
see
server.log for more details. An error has occurred```

And at the server.log almost the same:
```
[2024-04-26T10:26:24.547397-03:00] [GF 7.0.13] [SEVERE] []
[org.glassfish.admin.rest.resources.TemplateListOfResource]
[tid:
_ThreadID=90 _ThreadName=admin-listener(3)] [levelValue: 1000]
[[
Error occurred during deployment: Exception while deploying
the app
[challenge2] : JNDI lookup failed for the resource: Name:
MySqlUnit,
Lookup: jdbc/mysql, Type: javax.sql.DataSource -- Lookup failed
for
jdbc/mysql in



SerialContext[myEnv={java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl,

java.naming.factory.url.pkgs=com.sun.enterprise.naming}]. Please
see
server.log for more details.]]

[2024-04-26T10:26:24.548382-03:00] [GF 7.0.13] [INFO] []
[org.glassfish.admingui] [tid: _ThreadID=92
_ThreadName=admin-listener(5)] [levelValue: 800] [[
Exception Occurred :Error occurred during deployment:
Exception while
deploying the app [challenge2] : JNDI lookup failed for the
resource:
Name: MySqlUnit, Lookup: jdbc/mysql, Type: javax.sql.DataSource
--
Lookup failed for jdbc/mysql in



SerialContext[myEnv={java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl,

java.naming.factory.url.pkgs=com.sun.enterprise.naming}]. Please
see
server.log for more details.]]
```

I am trying to discover if there's any configuration which I
should to
do in persistence.xml or there is really any parameter on the
configuration pool which should I do.


Thank you,

Victor

-----Original Message-----
From: Victor Gimenez <victor.gimenez@xxxxxxxxxxxx>
Sent: Friday, April 26, 2024 8:47 AM
To: Sawamura, Hiroki/澤村 大輝
<sawamura.hiroki@xxxxxxxxxxx>
Subject: Re: [glassfish-dev] How to use Glassfish with MySQL or
any
database instead of Apache Derby

Em 2024-04-25 05:33, Hiroki Sawamura (Fujitsu) escreveu:
Hi

Hi!

Humm, it appears that the package of the MySQL implementation
class
has
changed.
  - mysql-connector-java-8.0.21.jar:
com/mysql/cj/jdbc/MysqlConnectionPoolDataSource.class
so, the data source class name that should be specified for
the JDBC
connection pool is
"com.mysql.cj.jdbc.MysqlConnectionPoolDataSource"
instead of "
com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource".

It worked here after that I changed this data source class
name!!

I am not familiar with JPA, but for JPA, you would specify the
JDBC
resource name as a data source in persistence.xml and then
inject its
unit name into EntityManager.
```persistence.xml
<persistence //snip//>
<persistence-unit name="MysqlUnit">
<jta-data-source>jdbc/mysql</jta-data-source>
</persistence-unit>
</persistence>
```

```java
public class YourAppDao{
@PersistenceContext(unitName="MysqlUnit")
private EntityManager em;
```

I did this modifications here in my persistence.xml file and
the .java
file which contains the EntityManager em variable declaration
and it
stayed like that
```
persistence.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns="https://jakarta.ee/xml/ns/persistence";

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";

xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence
https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd";
version="3.0">

<persistence-unit name="default">
<!--transaction-type="JTA"-->
<!--

<jta-data-source>java:comp/DefaultDataSource</jta-data-source>-->
<properties>
<property
name="jakarta.persistence.schema-generation.database.action"
value="drop-and-create"/>
</properties>
</persistence-unit>

<persistence-unit name="MySqlUnit">




<!--<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>-->
<jta-data-source>jdbc/mysql</jta-data-source>
<properties>
<!-- connection data -->
<property
name="jakarta.persistence.jdbc.driver"
value="com.mysql.cj.jdbc.Driver" />
<property
name="jakarta.persistence.jdbc.url"

value="jdbc:mysql://localhost/app?createDatabaseIfNotExist=true"
/>
<property
name="jakarta.persistence.jdbc.user" value="root" />
<property
name="jakarta.persistence.jdbc.password" value="admin" />
</properties>
</persistence-unit>
</persistence>
```


```
java
...
...
@PersistenceContext(unitName="MysqlUnit")
private EntityManager em;
...
...

```

The compilation with maven went good with mvn clear and mvn
package
working

But when I am gonna deploy on Glassfish GUI I am getting:

```
Error occurred during deployment: Exception while deploying the
app
[challenge2] : JNDI lookup failed for the resource: Name:
MySqlUnit,
Lookup: jdbc/mysql, Type: javax.sql.DataSource -- Lookup failed
for
jdbc/mysql in



SerialContext[myEnv={java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl,
java.naming.factory.url.pkgs=com.sun.enterprise.naming}].
Please see
server.log for more details.
```

I am trying to realize what I am doing wrong!


Thank you,

Victor

-----Original Message-----
From: Victor Gimenez <victor.gimenez@xxxxxxxxxxxx>
Sent: Thursday, April 25, 2024 4:41 PM
To: Sawamura, Hiroki/澤村 大輝
<sawamura.hiroki@xxxxxxxxxxx>; Glassfish
Dev
<glassfish-dev@xxxxxxxxxxx>
Subject: Re: [glassfish-dev] How to use Glassfish with MySQL
or any
database instead of Apache Derby

Em 2024-04-24 22:13, Hiroki Sawamura (Fujitsu) escreveu:
Hi

Hi Hiroki!

Class name is wrong or classpath is not set for :
com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
Please
check the server.log for more details.

Oops, I may have forgotten to mention something simple:
placing the
JDBC driver under the lib is to add it to the classpath, so
DAS(GlassFish) restart is required.

I entered sudo ./asadmin restart-domain to restart the
DAS(Glassfish)
and I successfully got this return statement:

```
Waiting finished after 30 ms.
Server instance is stopped, now we wait for the start on
localhost:4848
...
Waiting finished after 2,695 ms.
Successfully restarted the domain
Command restart-domain executed successfully.

```

But when I did that ping command the same error persisted, I
let the
mysql-connection-java-8.0.21.jar in



/home/victor/Downloads/web-7.0.13/glassfish7/glassfish/domains/domain1/lib/
path.

And about the step 4 referring these code snippets in which
.java
file should I refer them?

It is simply example of how to reference the JDBC resource
within
your
Jakarta EE application deployed to GlassFish. It is not a
specific
Java file.

And this ":" at the final of the code snippet is a ";" or
"}" to
finish the if block?

No. It indicates that the description of any process would
continue
after that.


Ohhhh now it made sense here to me and I realized, I
remembered now
that this DataSource dataSource is a variable responsible for
getting
the connection number as true or false to create the
statement, and
after query, update, delete and so on... In JPA I am using
EntityManager em variable to make the CRUD operations like
insert(em.persist), list data
(em.getCriteriaBuilder().createQuery...
do you know if I can able to use also the @Resource annotation
above
EntityManager em declaration?


Hiroki

-----Original Message-----
From: Victor Gimenez <victor.gimenez@xxxxxxxxxxxx>
Sent: Thursday, April 25, 2024 3:41 AM
To: glassfish-dev@xxxxxxxxxxx
Cc: Sawamura, Hiroki/澤村 大輝
<sawamura.hiroki@xxxxxxxxxxx>
Subject: Re: [glassfish-dev] How to use Glassfish with MySQL
or any
database instead of Apache Derby

Hello Hiroki! Thanks for your response,



I did the steps 1, 2 and 3 successfully obtaining as return:

```
JDBC connection pool mysql-pool created successfully.
Command create-jdbc-connection-pool executed successfully.
```

Only the connection check with ping returned me:
```
CLI031: Warning: Option "target" is obsolete and will be
ignored.
CLI031: Warning: Option "target" is obsolete and will be
ignored.
remote failure: Ping Connection Pool failed for



org.glassfish.resourcebase.resources.api.PoolInfo@bad58506[jndiName=my
sql-pool, applicationName=null, moduleName=null].
Class name is wrong or classpath is not set for :
com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
Please
check the server.log for more details.
Command ping-connection-pool failed.
```

I don't know what is missing in my configurations or if I
forgot to
set anything else.

And about the step 4 referring these code snippets in which
.java
file
should I refer them? And this ":" at the final of the code
snippet
is
a ";" or "}" to finish the if block?


Thank you,


In 2024-04-24 02:56, Hiroki Sawamura (Fujitsu) wrote:
Hi,

There are 4 simple steps to setting up DB with GlassFish.

1. Place JDBC driver in DAS lib dir.
$ mv mysql-connector-java-XXX.jar
glassfish7/glassfish/domains/domains/domain1/lib/

2. Create JDBC connection pool.
$ asadmin create-jdbc-connection-pool \
--restype javax.sql.ConnectionPoolDataSource \
--datasourceclassname
com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
\
--property



user=your_username:password=your_password:port=3306:databaseName=your
_
database_name:serverName=localhost
\
mysql-pool

It would be a good to check the connection with ping.
$ asadmin ping-connection-pool mysql-pool

3. Create JDBC resource.
$ asadmin create-jdbc-resource --target server
--connectionpoolid
mysql-pool jdbc/mysql

4. Refer in your application.
lookup is no longer needed. it can be easily injected and
used with
jakarta.annotation.Resource annotation.
```java
@Resource(lookup = "jdbc/mysql")
DataSource dataSource;
```
then, describe the operation as follows ```java
java.sql.Connection
con = dataSource.getConnection(); if (con.isValid(10)) {
java.sql.Statement stmt = con.createStatement();
java.sql.ResultSet result = stmt.executeQuery("SELECT
ID,NAME,PROGRAMMING_LANGUAGE FROM DEV")
:
```

Regards,
Hiroki

-----Original Message-----
From: glassfish-dev <glassfish-dev-bounces@xxxxxxxxxxx> On
Behalf
Of
Victor Gimenez via glassfish-dev
Sent: Wednesday, April 24, 2024 3:44 AM
To: glassfish-dev@xxxxxxxxxxx
Cc: Victor Gimenez <victor.gimenez@xxxxxxxxxxxx>
Subject: [glassfish-dev] How to use Glassfish with MySQL or
any
database instead of Apache Derby

Hello there,



I am very new to Glassfish and Jakarta EE which I am
learning
nowadays, I would like to know what I should do to add MySQL
or any
database instead of Apache Derby which is configured as the
default
database server? I am very stuck reading the documentation
and
without know which files should I configure to add.


Thanks in advance,

--
Victor Borghi Gimenez


Computer Science M.Sc. - Center for Mathematics, Computing
and
Cognition
- Federal University of ABC (UFABC)
System Analysis and Development Technologist - São Caetano
do Sul
College of Technology (FATEC-SCS)
_______________________________________________
glassfish-dev mailing list
glassfish-dev@xxxxxxxxxxx
To unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/glassfish-dev
_______________________________________________
glassfish-dev mailing list
glassfish-dev@xxxxxxxxxxx
To unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/glassfish-dev
_______________________________________________
glassfish-dev mailing list
glassfish-dev@xxxxxxxxxxx
To unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/glassfish-dev
_______________________________________________
glassfish-dev mailing list
glassfish-dev@xxxxxxxxxxx
To unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/glassfish-dev
_______________________________________________
glassfish-dev mailing list
glassfish-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/glassfish-dev


Back to the top