MongoDB с отношениями наследования - PullRequest
0 голосов
/ 18 июня 2020
I have below classes with relationship .

Job
 -- name
 -- description
 -- List(Task)

Task
 -- name
 -- description

scriptTask extends Task
  -- script

apiTask extends Task
 -- apiMethond
 -- url

when I save the Job with the both script and apitask value, save works fine. I could see the task's field name and description for both task's in db.
{
"jobName" : "jobName", 
"tasks" : [
    {
        "script" : "whoami", 
        "name" : "script", 
        "description" : "script", 
        "_class" : "com.model.scriptTask"
    }, 
    {
        "apiMethond" : "GET", 
        "url" : "/user", 
        "name" : "ansible", 
        "description" : "ansible", 
        "_class" : "com.model.apiTask"
    }
    ]
}
But when I fetch the details using repository.findone(), I am not getting the task's name and description field
{
    "userId": "5eeaf6584c24665e1cdaf400",
    "jobName": "jobName",
    "tasks": [
        {
            "script": "whoami"
        },
        {
            "apiMethond" : "GET", 
            "url" : "/user", 
        }
    ]
 }

How to get the super class fields from db.
I am using spring-boot-starter-data-mongodb to do CRUD operation.
Thanks for your help.
...