Subobjects inserted with null values with Elasticsearch and DTOs
See original GitHub issueOverview 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
- Create a new entitiy
- 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:
- While creating an object, after
entity = einsatzortRepository.save(entity);
entity still contains incomplete fields (as it was received / mapped from the DTO) - 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:
- Created 6 years ago
- Reactions:2
- Comments:22 (17 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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:
we now have:
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?
@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 😃