generator-jhipster: Elasticsearch Errors with circular related objects
Example Project
https://github.com/hepaestus/test-app-one
Reproduce the error
See The Test Project: https://github.com/hepaestus/test-app-one#development Once you have the it set up.
- Open http://localhost:9000/ and login as admin.
- Select the Cars entity in the menu.
- Click button to Edit a car.
- Attempt to save passengers to a car.
This should trigger the error and show an error in the alert area:
Handler dispatch failed; nested exception is java.lang.StackOverflowError
See below for more of the error output.
JHipster Version(s)
test-app-one@0.0.1-SNAPSHOT /home/pete/git/test-app-one
└── generator-jhipster@7.1.0
JHipster configuration, a .yo-rc.json file generated in the root folder
INFO! Using JHipster version installed locally in current project’s node_modules Welcome to the JHipster Information Sub-Generator
JHipster Version(s)
test-app-one@0.0.1-SNAPSHOT /home/pete/git/test-app-one
└── generator-jhipster@7.1.0
JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
"generator-jhipster": {
"authenticationType": "jwt",
"cacheProvider": "ehcache",
"clientFramework": "angularX",
"serverPort": "8080",
"serviceDiscoveryType": false,
"skipUserManagement": false,
"withAdminUi": true,
"baseName": "testAppOne",
"buildTool": "maven",
"databaseType": "sql",
"devDatabaseType": "mysql",
"enableHibernateCache": true,
"enableSwaggerCodegen": false,
"enableTranslation": false,
"jhiPrefix": "jhi",
"languages": ["en", "fr"],
"messageBroker": false,
"prodDatabaseType": "mysql",
"searchEngine": "elasticsearch",
"skipClient": false,
"testFrameworks": [],
"websocket": false,
"applicationType": "monolith",
"blueprints": [],
"clientPackageManager": "npm",
"clientTheme": "none",
"creationTimestamp": 1629828268927,
"dtoSuffix": "DTO",
"jhipsterVersion": "7.1.0",
"jwtSecretKey": "YourJWTSecretKeyWasReplacedByThisMeaninglessTextByTheJHipsterInfoCommandForObviousSecurityReasons",
"nativeLanguage": "en",
"otherModules": [],
"packageName": "com.hepaestus.testappone",
"packageFolder": "com/hepaestus/testappone",
"reactive": false,
"skipServer": false,
"entitySuffix": "",
"applicationIndex": 0,
"entities": ["Car", "Person", "Shoe", "Driver"],
"clientThemeVariant": "",
"skipCheckLengthOfIdentifier": false,
"skipFakeData": false,
"pages": [],
"devServerPort": 4200,
"lastLiquibaseTimestamp": 1629828508000
}
}
JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
entity Car {
make String
model String
year LocalDate
}
entity Person {
name String
}
entity Shoe {
shoeSize Integer min(4) max(18)
}
entity Driver {
licenseNumber String required pattern(/^[A-Z][a-z]{6}[0-9]{1}/)
}
relationship OneToOne {
Person{user} to User
Driver{person(name) required} to Person{driver}
}
relationship OneToMany {
Driver{car required} to Car{driver required}
}
relationship ManyToMany {
Car{passengers} to Person{car}
Person{shoe} to Shoe{person}
}
dto Car, Person, Shoe, Driver with mapstruct
service Car, Person, Shoe, Driver with serviceClass
search Car, Person, Shoe, Driver with elasticsearch
Environment and Tools
openjdk version “11.0.11” 2021-04-20 OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.10) OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.10, mixed mode, sharing)
git version 2.27.0
node: v16.3.0
npm: 7.20.5
Docker version 20.10.8, build 3967b7d
docker-compose version 1.29.2, build 5becea4c
No change to package.json was detected. No package manager install will be executed. Congratulations, JHipster execution is complete! Sponsored with ❤️ by @oktadev.
No change to package.json was detected. No package manager install will be executed.
Overview of the issue
When using elasticsearch and saving entities a error shows up. For example saving the Car entity with a driver and passengers will throw an error:
Handler dispatch failed; nested exception is java.lang.StackOverflowError: Delayed StackOverflowError due to ReservedStackAccess annotated method
2021-09-02 13:28:25.979 DEBUG 256258 --- [ XNIO-1 task-3] c.h.testappone.web.rest.CarResource : Enter: updateCar() with argument[s] = [2, CarDTO{id=2, make='one-to-one', model='Cuban Profit-focused', driver=null, passengers=[PersonDTO{id=1, name='Alaska', shoes=[]}, PersonDTO{id=2, name='utilize', shoes=[]}]}]
2021-09-02 13:28:25.980 DEBUG 256258 --- [ XNIO-1 task-3] c.h.testappone.web.rest.CarResource : REST request to update Car : 2, CarDTO{id=2, make='one-to-one', model='Cuban Profit-focused', driver=null, passengers=[PersonDTO{id=1, name='Alaska', shoes=[]}, PersonDTO{id=2, name='utilize', shoes=[]}]}
2021-09-02 13:28:25.982 DEBUG 256258 --- [ XNIO-1 task-3] org.hibernate.SQL : select count(*) as col_0_0_ from car car0_ where car0_.id=?
2021-09-02 13:28:25.984 DEBUG 256258 --- [ XNIO-1 task-3] c.h.testappone.service.CarService : Enter: save() with argument[s] = [CarDTO{id=2, make='one-to-one', model='Cuban Profit-focused', driver=null, passengers=[PersonDTO{id=1, name='Alaska', shoes=[]}, PersonDTO{id=2, name='utilize', shoes=[]}]}]
2021-09-02 13:28:25.984 DEBUG 256258 --- [ XNIO-1 task-3] c.h.testappone.service.CarService : Request to save Car : CarDTO{id=2, make='one-to-one', model='Cuban Profit-focused', driver=null, passengers=[PersonDTO{id=1, name='Alaska', shoes=[]}, PersonDTO{id=2, name='utilize', shoes=[]}]}
2021-09-02 13:28:25.995 DEBUG 256258 --- [ XNIO-1 task-3] org.hibernate.SQL : select driver0_.id as id1_1_1_, driver0_.license_number as license_2_1_1_, driver0_.person_id as person_i3_1_1_, person1_.id as id1_5_0_, person1_.name as name2_5_0_ from driver driver0_ left outer join person person1_ on driver0_.person_id=person1_.id where driver0_.person_id=?
2021-09-02 13:28:25.997 DEBUG 256258 --- [ XNIO-1 task-3] org.hibernate.SQL : select driver0_.id as id1_1_1_, driver0_.license_number as license_2_1_1_, driver0_.person_id as person_i3_1_1_, person1_.id as id1_5_0_, person1_.name as name2_5_0_ from driver driver0_ left outer join person person1_ on driver0_.person_id=person1_.id where driver0_.person_id=?
2021-09-02 13:28:26.027 ERROR 256258 --- [ XNIO-1 task-3] c.h.testappone.service.CarService : Exception in save() with cause = 'NULL' and exception = 'null'
java.lang.StackOverflowError: null
at java.base/java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.java:329)
at org.springframework.data.util.ClassTypeInformation.from(ClassTypeInformation.java:71)
at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:201)
at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:87)
at org.springframework.data.mapping.context.MappingContext.getRequiredPersistentEntity(MappingContext.java:73)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.writeEntity(MappingElasticsearchConverter.java:636)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.getWriteComplexValue(MappingElasticsearchConverter.java:627)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.writeProperty(MappingElasticsearchConverter.java:601)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.writeProperties(MappingElasticsearchConverter.java:553)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.writeEntity(MappingElasticsearchConverter.java:511)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.writeEntity(MappingElasticsearchConverter.java:636)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.getWriteComplexValue(MappingElasticsearchConverter.java:627)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.writeProperty(MappingElasticsearchConverter.java:601)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.writeProperties(MappingElasticsearchConverter.java:553)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.writeEntity(MappingElasticsearchConverter.java:511)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.writeEntity(MappingElasticsearchConverter.java:636)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.getWriteComplexValue(MappingElasticsearchConverter.java:627)
...
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.writeEntity(MappingElasticsearchConverter.java:636)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.getWriteComplexValue(MappingElasticsearchConverter.java:627)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.writeProperty(MappingElasticsearchConverter.java:601)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.writeProperties(MappingElasticsearchConverter.java:553)
2021-09-02 13:28:26.059 ERROR 256258 --- [ XNIO-1 task-3] o.z.problem.spring.common.AdviceTraits : Internal Server Error
org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.StackOverflowError
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1078)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:920)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:520)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:584)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:113)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:327)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:115)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:81)
...
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.writeProperties(MappingElasticsearchConverter.java:553)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.writeEntity(MappingElasticsearchConverter.java:511)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.writeEntity(MappingElasticsearchConverter.java:636)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.getWriteComplexValue(MappingElasticsearchConverter.java:627)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.writeProperty(MappingElasticsearchConverter.java:601)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.writeProperties(MappingElasticsearchConverter.java:553)
2021-09-02 13:28:26.076 WARN 256258 --- [ XNIO-1 task-3] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.StackOverflowError]
Motivation for or Use Case
I would like to use elasticsearch out of the box as one would expect it to work.
Reproduce the error
https://github.com/hepaestus/test-app-one#development
See the Example Project here: https://github.com/hepaestus/test-app-one
Related issues
Cannot save entities due to recursion error.
Suggest a Fix
I am not sure of how to fix but I was curious of this might help:
@Field(type = FieldType.Nested, ignoreFields = {"children"})
Entity configuration(s) entityName.json files generated in the .jhipster directory
{
"name": "Car",
"fields": [
{
"fieldName": "make",
"fieldType": "String"
},
{
"fieldName": "model",
"fieldType": "String"
}
],
"relationships": [
{
"relationshipType": "many-to-one",
"otherEntityName": "driver",
"otherEntityRelationshipName": "car",
"relationshipName": "driver"
},
{
"relationshipType": "many-to-many",
"otherEntityName": "person",
"otherEntityRelationshipName": "car",
"relationshipName": "passengers",
"ownerSide": true
}
],
"entityTableName": "car",
"dto": "mapstruct",
"pagination": "no",
"service": "serviceClass",
"jpaMetamodelFiltering": false,
"fluentMethods": true,
"readOnly": false,
"embedded": false,
"applications": ["testAppOne"],
"searchEngine": "elasticsearch",
"changelogDate": "20210824180528"
}
{
"name": "Driver",
"fields": [
{
"fieldName": "licenseNumber",
"fieldType": "String"
}
],
"relationships": [
{
"relationshipType": "one-to-one",
"otherEntityName": "person",
"otherEntityRelationshipName": "driver",
"relationshipName": "person",
"ownerSide": true
},
{
"relationshipType": "one-to-many",
"otherEntityName": "car",
"otherEntityRelationshipName": "driver",
"relationshipName": "car"
}
],
"entityTableName": "driver",
"dto": "mapstruct",
"pagination": "no",
"service": "serviceClass",
"jpaMetamodelFiltering": false,
"fluentMethods": true,
"readOnly": false,
"embedded": false,
"applications": ["testAppOne"],
"searchEngine": "elasticsearch",
"changelogDate": "20210824180828"
}
{
"name": "Person",
"fields": [
{
"fieldName": "name",
"fieldType": "String"
}
],
"relationships": [
{
"relationshipType": "one-to-one",
"otherEntityName": "driver",
"otherEntityRelationshipName": "person",
"relationshipName": "driver",
"ownerSide": false
},
{
"relationshipType": "many-to-many",
"otherEntityName": "car",
"otherEntityRelationshipName": "passengers",
"relationshipName": "car",
"ownerSide": false
},
{
"relationshipType": "many-to-many",
"otherEntityName": "shoe",
"otherEntityRelationshipName": "person",
"relationshipName": "shoe",
"ownerSide": false
}
],
"entityTableName": "person",
"dto": "mapstruct",
"pagination": "no",
"service": "serviceClass",
"jpaMetamodelFiltering": false,
"fluentMethods": true,
"readOnly": false,
"embedded": false,
"applications": ["testAppOne"],
"searchEngine": "elasticsearch",
"changelogDate": "20210824180628"
}
{
"name": "Shoe",
"fields": [
{
"fieldName": "shoeSize",
"fieldType": "Integer"
}
],
"relationships": [
{
"relationshipType": "many-to-many",
"otherEntityName": "person",
"otherEntityRelationshipName": "shoe",
"relationshipName": "person",
"ownerSide": true
}
],
"entityTableName": "shoe",
"dto": "mapstruct",
"pagination": "no",
"service": "serviceClass",
"jpaMetamodelFiltering": false,
"fluentMethods": true,
"readOnly": false,
"embedded": false,
"applications": ["testAppOne"],
"searchEngine": "elasticsearch",
"changelogDate": "20210824180728"
}
Browsers and Operating System
Ubuntu and Chrome
- Checking this box is mandatory (this is just to show you read everything)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 25 (8 by maintainers)
Hello, sorry for the late reply, these last weeks have been crazy.
Here is an example of what I’ve done to use Converters and configure spring data to use them.
https://github.com/bkenn/eleasticsexample
here is the commit with the work: https://github.com/bkenn/eleasticsexample/commit/6d3875d539e40ddaadbe970ead35650c1a5ca34e
for running locally:
If you want to see it the StackOverflowError, remove the mappers from ElasticsearchConfiguration.
Do what you will with this example. I don’t this is the best workaround. I would rather find something better than workaround spring data.
I’m facing the same issue