MorphiaOrg / MorphiaOrg/morphia

ClassNotFoundException during package mapping in application server

Open
#4,066 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug forward-port
Dominant language
Java
Stars
1.7k
Forks
449
Avg merge
7m
Merged PRs (30d)
10

Description

Duplicate of #4038 for milestone 3.0.0


Describe the bug
Deploying an ear application that uses Morphia 2.5.1 and MongoDB Driver 5.6.1 (as provided in the lib/ext of the domain) into an application server like Payara (5.2022.5).
When the application starts and should map the package de.asheep.classloaderexample then no entities are mapped because line 621 of Mapper.java classes.add(Class.forName(classInfo.getName())); does not find the corresponding classes and throws an ClassNotFoundException which is ignored.

To Reproduce
Steps to reproduce the behavior:

  1. Build the example with mvn clean package
  2. Provide the mongodb 5.6.1 jars in the lib/ext directory of the domain of the application sever
  3. Deploy the ear file into a domain of the application sever
  4. Start the application

Expected behavior
The entities of the package de.asheep.classloaderexample should be found and mapped.

  • Server Version: Payara 5.2022.5
  • Driver Version: 5.6.1
  • Morphia Version: 2.5.1

Additional context
It seems that the used ClassLoader is not the correct one. Changing the line to classes.add(Class.forName(classInfo.getName(), true, Thread.currentThread().getContextClassLoader())); will result in finding the correct classes.

ClassloaderExample.zip

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading Mapper.java around line 621 and compare this duplicate with issue #4038, then build the attached example with mvn clean package. Reproduce the Payara deployment using the specified MongoDB driver jars and verify that entities in de.asheep.classloaderexample are found and mapped without the ClassNotFoundException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, mongodb
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.