Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JPADeployer fails to get a reference to a data source #25377

Open
naotsugu opened this issue Feb 17, 2025 · 1 comment
Open

JPADeployer fails to get a reference to a data source #25377

naotsugu opened this issue Feb 17, 2025 · 1 comment

Comments

@naotsugu
Copy link

Environment Details

GlassFish Version (and build number): 8.0.0-M9
JDK version: 21
OS: any

Problem Description

The data source defined in @DataSourceDefinition cannot be referenced from persistence.xml.

Works for 8.0.0-M8, but exception for 8.0.0-M9.

Probably affected by the #25198 modifications.

The following simple definitions are exceptions(See https://github.com/naotsugu/playground-glassfish/tree/gf-issue-JPADeployer).

@DataSourceDefinition(
        name = DataSourceConfig.DS_NAME,
        className = "org.h2.jdbcx.JdbcDataSource",
        url = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1")
<persistence version="3.2"
             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_2.xsd">
    <persistence-unit name="default" transaction-type="JTA">
        <jta-data-source>java:app/App/MainDs</jta-data-source>
        <properties>
            <property name="jakarta.persistence.schema-generation.database.action" value="create"/>
        </properties>
    </persistence-unit>
</persistence>

If you change the commented part of app/build.gradle.kts to M8, the exception will no longer occur.

    // download glassfish-embedded-all
    // val url = "https://repo1.maven.org/maven2/org/glassfish/main/extras/glassfish-embedded-all/8.0.0-M8/glassfish-embedded-all-8.0.0-M8.jar"
    // val dest = layout.projectDirectory.file("glassfish-embedded-all-8.0.0-M8.jar")
    val url = "https://repo1.maven.org/maven2/org/glassfish/main/extras/glassfish-embedded-all/8.0.0-M9/glassfish-embedded-all-8.0.0-M9.jar"
    val dest = layout.projectDirectory.file("glassfish-embedded-all-8.0.0-M9.jar")

The stack traces are as follows.

SEVERE: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method
java.lang.RuntimeException: Invalid resource: org.glassfish.resourcebase.resources.api.ResourceInfo@a358dd17[jndiName=java:app/App/MainDs__pm, applicationName=app, moduleName=null]
        at com.sun.enterprise.connectors.ConnectorRuntime.lookupDataSourceInDAS(ConnectorRuntime.java:565)
        at com.sun.enterprise.connectors.ConnectorRuntime.lookupPMResource(ConnectorRuntime.java:503)
        at org.glassfish.persistence.common.PersistenceHelper.lookupPMResource(PersistenceHelper.java:48)
        at org.glassfish.persistence.jpa.ProviderContainerContractInfoBase.lookupDataSource(ProviderContainerContractInfoBase.java:56)
        at org.glassfish.persistence.jpa.PersistenceUnitInfoImpl.<init>(PersistenceUnitInfoImpl.java:81)
        at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:161)
        at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:126)
        at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:325)
        at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:546)
        at org.glassfish.persistence.jpa.JPADeployer.createEntityManagerFactories(JPADeployer.java:331)
        at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:984)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:467)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:257)
        at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:474)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:574)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:570)
        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:569)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:600)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:592)
        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:591)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1484)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1862)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1738)
        at com.sun.enterprise.admin.cli.embeddable.CommandExecutorImpl.executeCommand(CommandExecutorImpl.java:147)
        at com.sun.enterprise.admin.cli.embeddable.CommandExecutorImpl.run(CommandExecutorImpl.java:73)
        at org.glassfish.runnablejar.UberMain.executeCommandFromString(UberMain.java:192)
        at org.glassfish.runnablejar.UberMain.run(UberMain.java:113)
        at org.glassfish.runnablejar.UberMain.main(UberMain.java:92)
Caused by: com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Invalid resource: org.glassfish.resourcebase.resources.api.ResourceInfo@a358dd17[jndiName=java:app/App/MainDs__pm, applicationName=app, moduleName=null]
        at org.glassfish.jdbcruntime.service.JdbcDataSource.validateResource(JdbcDataSource.java:62)
        at org.glassfish.jdbcruntime.service.JdbcDataSource.<init>(JdbcDataSource.java:44)
        at org.glassfish.jdbcruntime.JdbcRuntimeExtension.lookupDataSourceInDAS(JdbcRuntimeExtension.java:119)
        at org.glassfish.jdbcruntime.JdbcRuntimeExtension.lookupDataSourceInDAS(JdbcRuntimeExtension.java:56)
        at com.sun.enterprise.connectors.ConnectorRuntime.lookupDataSourceInDAS(ConnectorRuntime.java:561)
        ... 32 more

Steps to reproduce

git clone https://github.com/naotsugu/playground-glassfish.git
cd playground-glassfish
git fetch origin gf-issue-JPADeployer
git checkout gf-issue-JPADeployer
./gradlew run

Impact of Issue

Data source cannot be defined.

@pzygielo
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants