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 9029141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:10:44+00:00 2026-06-16T07:10:44+00:00

I am using Datanucleus/JDO to persist objects in a MongoDB DB. I try to

  • 0

I am using Datanucleus/JDO to persist objects in a MongoDB DB.
I try to persist an object containing a Map, which value type is an abstract class.

When I try to persist an instance of that object, fields of the abstract class are persisted, but not those of the child class.

Below is some code as an example.

Zoo.java

    @PersistenceCapable
    public class Zoo {

            @Persistent
            private String fieldZoo;
            @Persistent
            private Map<String, Animal> mapStringAnimal;

            // etc... basic constructor...
    }

Animal.java

    @PersistenceCapable(embeddedOnly = "true")
    public abstract class Animal {

            @Persistent
            private String  fieldAnimal;

    }

Dog.java

    @PersistenceCapable(embeddedOnly = "true")
    public class Dog extends Animal {

            @Persistent
            private String  fieldDog;

    }

Test.java

    public static void main(String[] args) {
            Map<String, Animal> mapStringAnimal = new HashMap<String, Animal>();
            Dog dog = new Dog("valueFieldAnimal", "valueFieldDog");
            mapStringAnimal.put("dogKey", dog);
            Zoo zoo = new Zoo("valueFieldZoo", mapStringAnimal);

            Properties properties = new Properties();
            properties.setProperty("javax.jdo.PersistenceManagerFactoryClass", "org.datanucleus.api.jdo.JDOPersistenceManagerFactory");
            properties.setProperty("javax.jdo.option.ConnectionURL", "mongodb:/dbtest");
            properties.setProperty("javax.jdo.option.Mapping", "mongodb");
            properties.setProperty("datanucleus.autoCreateSchema", "true");
            PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(properties);
            PersistenceManager pm = pmf.getPersistenceManager();

            pm.makePersistent(zoo);
            pm.close();
    }

And when I look at MongoDB:

    > db.Zoo.find().pretty();

    {
            "_id" : ObjectId("50d2f5f7e4b0cae285990b2d"),
            "fieldZoo" : "valueFieldZoo",
            "mapStringAnimal" : [
                    {
                            "key" : "dogKey",
                            "value" : {
                                    "fieldAnimal" : "valueFieldAnimal"
                            }
                    }
            ]
    }
  • 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-06-16T07:10:46+00:00Added an answer on June 16, 2026 at 7:10 am

    Yes, but DataNucleus doesn’t support embedded inherited Map keys/values. It does support embedded inherited Collection elements (part of not-yet-released JDO3.1), but not the equivalent for Maps. Obviously the code is open source and anyone could dive in and contribute it (once you’ve added a discriminator to “Animal” of course).

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

Sidebar

Related Questions

I am using DataNucleus 3.0.0-release JDO implementation to connect my Java app to MongoDB.
Using DataNucleus, I have been happy using an abstract base class to provide a
I'm trying to map an existing mongodb database to domain objects using datanuclues (3.0.0-m6)
I am using DataNucleus' implement of JDO on a local H2 database. I want
i am using gwt with jdo datanucleus. i have requirement to get child with
I am using Datanucleus JDO on top of HSqlDb. I would like to execute
How can we enable compression for a specific table using jdo and datanucleus in
I am using DataNucleus's implementation of JDO on an H2 database instance opened in
I am using DataNucleus' implementation of JDO to populate a table on a local
Assuming one has an operational Java application using DataNucleus's implementation of JDO to access

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.