question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Subobjects inserted with null values with Elasticsearch and DTOs

See original GitHub issue
Overview of the issue

While creating a entity, it is saved both to the database and to Elasticsearch by the EntityServiceImpl’s save method. While creating an entity, all sub-objects are only saved with their ID, all other fields are null. When the entity is updated, all fields are present.

Motivation for or Use Case

This results into an incomplete state in Elasticsearch and can even produce functional problems, e.g. when the search should include fields of linked entities.

Reproduce the error
  1. Create a new entitiy
  2. Look into Elasticsearch index or try to search for content present in a field of a linked entity.
Related issues

n/a

Suggest a Fix

We found out that:

  1. While creating an object, after entity = einsatzortRepository.save(entity); entity still contains incomplete fields (as it was received / mapped from the DTO)
  2. While updating an object, after entity = einsatzortRepository.save(entity); entity has been filled from the database

We only have a workaround for our bug and did not come up with a real idea for a fix yet. The workaround is: If the EntityResource calls save() on the service twice, the data is persisted in Elasticsearch correctly.

JHipster Version(s)

4.6.2

JHipster configuration

.yo-rc.json:

{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "de.XXXX",
      "nativeLanguage": "de"
    },
    "jhipsterVersion": "4.6.2",
    "baseName": "xxxx",
    "packageName": "de.XXXX",
    "packageFolder": "de/XXXX",
    "serverPort": "8080",
    "authenticationType": "oauth2",
    "hibernateCache": "no",
    "clusteredHttpSession": false,
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "h2Memory",
    "prodDatabaseType": "oracle",
    "searchEngine": "elasticsearch",
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "buildTool": "maven",
    "enableSocialSignIn": false,
    "clientFramework": "angularX",
    "useSass": true,
    "clientPackageManager": "yarn",
    "applicationType": "monolith",
    "testFrameworks": [
      "protractor"
    ],
    "jhiPrefix": "jhi",
    "enableTranslation": true,
    "nativeLanguage": "de",
    "languages": [
      "de"
    ]
  }
}
Entity configuration(s) entityName.json files generated in the .jhipster directory

main.json

{
    "fluentMethods": true,
    "relationships": [
        {
            "relationshipType": "many-to-one",
            "relationshipValidateRules": "required",
            "relationshipName": "otherEntity",
            "otherEntityName": "otherentity",
            "otherEntityField": "name"
        }
    ],
    "fields": [
        {
            "fieldName": "name",
            "fieldType": "String",
            "fieldValidateRules": [
                "required",
                "minlength",
                "maxlength",
                "pattern"
            ],
            "fieldValidateRulesMinlength": 2,
            "fieldValidateRulesMaxlength": 50,
            "fieldValidateRulesPattern": "^[A-ZÄÖÜa-zäöüß\\- ]*$"
        },
       // ,,,
    ],
    "changelogDate": "20170704124210",
    "entityTableName": "eso",
    "dto": "mapstruct",
    "pagination": "infinite-scroll",
    "service": "serviceImpl"
}
Browsers and Operating System

Unrelated.

  • Checking this box is mandatory (this is just to show you read everything)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:22 (17 by maintainers)

github_iconTop GitHub Comments

3reactions
stieler-itcommented, Nov 23, 2017

Since this problem came up again we had to find a solution without re-writing the search functionality from scratch.

Basicall, in every Mapper, instead of:

    default Office fromId(Long id) {
        if (id == null) {
            return null;
        }
        Office office = new Office();
        office.setId(id);
        return office;
    }

we now have:

    public Office fromId(Long id) {
        if (id == null) {
            return null;
        }
        return officeRepository.findOne(id);
    }

This probably means some database calls that would not be necessary. However, every saved entity contains all its nested objects. This will save as from a bunch of bugs that would have been reported otherwise.

What do you think?

1reaction
pascalgrimaudcommented, Oct 11, 2019

@sdyson : I understand the need, but if you read the previous comment, it has been closed simply because no one wants to try to implement something. So maybe it’s minor or people don’t care about this issue.

Anyway, you’re welcome to propose a solution here 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

null_value | Elasticsearch Guide [8.5] | Elastic
When a field is set to null , (or an empty array or an array of null values) it is treated as though...
Read more >
Query elastic search documents, where there is null value for ...
I am struggling with elastic search query. These are example documents, which I would to query. These are documents with generic properties
Read more >
Spring Data MongoDB - Reference Documentation
When including null values in the ExampleSpec , Spring Data Mongo uses embedded document matching instead of dot notation property matching. Doing so...
Read more >
History - Apache Calcite
[CALCITE-4980] Babel parser support MySQL NULL-safe equal operator '<=> ... [CALCITE-3046] CompileException when inserting casted value of composited user ...
Read more >
Users Guide - DbVisualizer 13.0
A new, empty SQL Commander tab is created by clicking the Create SQL Commander ... that matches the foreign key value when a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found