Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3284124
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:07:09+00:00 2026-05-17T20:07:09+00:00

I’ve created a simple webapp using Spring & Jetty, and am creating a hello

  • 0

I’ve created a simple webapp using Spring & Jetty, and am creating a hello world JDO test using DataNucleus & DB4O.

I can persist a class no problem, but when I go to query for the class I get a ClassCastException, can’t cast a.b.c.MyClass to a.b.c.MyClass.

When I examine the classloader of the original object I created, it’s [WebAppClassLoader@1592226291], naturally it’s springs WebApp classloader.

I am performing both the persist operation and query operation in the same servlet method, when I re-read the object from the DB with a simple query I get back a set of a.b.c.MyClass objects from the DB, but the classloader is [sun.misc.Launcher$AppClassLoader@5acac268], thus the exception.

Following the DataNucleus docs here http://www.datanucleus.org/extensions/classloader_resolver.html

…the JDO2 class-loading mechanism
utilises 3 class loaders

* When creating the PersistenceManagerFactory you can
specify a class loader. This is used
first if specified
* The second class loader to try is the class loader for the current
thread.
* The third class loader to try is the class loader for the PMF context.

I covered the first two options documented, and verified that the classloader is the WebAppClassLoader in the Servlet with these debug steps in the servlet:

Thread.currentThread().getContextClassLoader().toString()
((JDOPersistenceManagerFactory)pm.getPersistenceManagerFactory()).getPrimaryClassLoader().toString()

Both yield [WebAppClassLoader@1592226291] as the classloader.

I’m not sure where I’m going wrong here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:07:10+00:00Added an answer on May 17, 2026 at 8:07 pm

    My earlier comment as an answer:

    This exception indicates that it is a class loader issue. Compare the class-loader of the object and the class you’re using for the cast.

    ClassLoader loaderOfObject = theObject.getClass().getClassLoader();
    ClassLoader loaderOfLocalClass = MyClass.getClassLoader();
    // have to be the same.
    assert loaderOfObject.equals(loaderOfLocalClass);
    

    Btw: If db4o is using the wrong class-loader. You can change that by configuring the class-loader explicit.

        EmbeddedConfiguration configuration = Db4oEmbedded.newConfiguration();
        JdkReflector reflector = new JdkReflector(Thread.currentThread().getContextClassLoader());
        configuration.common().reflectWith(reflector);
        ObjectContainer container = Db4oEmbedded.openFile(configuration, "database.db4o");
    

    When a single class-loader isn’t enough: You can also pass a instance of the db4o-interface JdkLoader instead of a class-loader. In there you can implement any class-lookup method. For example to look up in multiple class loaders.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.