Generator-jhipster: Error creating relationships with MongoDB and Elastic Search together

Created on 28 Oct 2018  ·  7Comments  ·  Source: jhipster/generator-jhipster

Overview of the issue

I am trying to create relationships b/w entities in my application generated using JHipster with MongoDB and Elasticsearch selected as options. We are currently using Microservice architecture, but I noticed that the same issue is happening in Monoliths as well. So, created a small sample monolith application for simplicity sake to demonstrate the issue. If you needed more info about the application it is also available here

The relationships b/w entities work as expected if Elastic Search is not selected, but when ES is selected, I am getting the following error:

10:51:06.067 [restartedMain] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'postServiceImpl' defined in file [/Users/deshetti/Projects/mongo-es-issue/build/classes/java/main/com/factly/dega/service/impl/PostServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'postSearchRepository': Invocation of init method failed; nested exception is java.lang.IllegalStateException: No association found!
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:197) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1267) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1124) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
        at com.factly.dega.JhipsterApp.main(JhipsterApp.java:62) [main/:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_162]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_162]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_162]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_162]
        at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.0.5.RELEASE.jar:2.0.5.RELEASE]
##### **Reproduce the error** - Create an application with MongoDB and ElasticSearch - Create a couple of entities with relationships b/w them ##### **Suggest a Fix** **UPDATE:** @oddiraju was able to fix the issue in our application and here is the commit for the fix in the sample application: https://github.com/deshetti/mongo-es-issue/commit/2c54dec25ced959cf0faac3930cecdfdb082a3d7 We are not familiar with how to apply this fix in the JHipster Generator. ##### **JHipster Version(s)**
[email protected] /Users/deshetti/Projects/mongo-es-issue
└── [email protected] 

##### **JHipster configuration**
.yo-rc.json file
{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "com.factly.dega",
      "nativeLanguage": "en"
    },
    "jhipsterVersion": "5.5.0",
    "applicationType": "monolith",
    "baseName": "jhipster",
    "packageName": "com.factly.dega",
    "packageFolder": "com/factly/dega",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "cacheProvider": "hazelcast",
    "enableHibernateCache": false,
    "websocket": false,
    "databaseType": "mongodb",
    "devDatabaseType": "mongodb",
    "prodDatabaseType": "mongodb",
    "searchEngine": "elasticsearch",
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "buildTool": "gradle",
    "enableSwaggerCodegen": false,
    "jwtSecretKey": "bXktc2VjcmV0LXRva2VuLXRvLWNoYW5nZS1pbi1wcm9kdWN0aW9uLWFuZC10by1rZWVwLWluLWEtc2VjdXJlLXBsYWNl",
    "clientFramework": "angularX",
    "useSass": true,
    "clientPackageManager": "npm",
    "testFrameworks": [
      "gatling",
      "cucumber",
      "protractor"
    ],
    "jhiPrefix": "jhi",
    "enableTranslation": true,
    "nativeLanguage": "en",
    "languages": [
      "en",
      "hi"
    ]
  }
}

Entity configuration(s) entityName.json files generated in the .jhipster directory


JDL entity definitions

entity Post {
  name String required
}
entity Tag {
  name String required
}
relationship ManyToMany {
  Post{tag(name)} to Tag{post}
}

dto Post, Tag with mapstruct
paginate Post, Tag with pagination
service Post, Tag with serviceImpl
search Post, Tag with elasticsearch

Environment and Tools

java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)

git version 2.14.3

node: v8.11.4

npm: 6.4.0

yeoman: 2.0.3

yarn: 1.9.4

Docker version 18.06.1-ce, build e68fc7a

docker-compose version 1.22.0, build f46880f

Browsers and Operating System

MacOS version 10.14

  • [x] Checking this box is mandatory (this is just to show you read everything)
$100

Most helpful comment

@oddiraju I added a pull request with your fix. This issue has a bug bounty tag on it. When it's merged you should claim it. The work was yours (i've just pasted it where needed). Cheers!

All 7 comments

We fixed this issue by implementing CustomElasticsearchMappingContext in ElasticsearchConfiguration
Here is the commit to our branch.
https://github.com/deshetti/mongo-es-issue/commit/2c54dec25ced959cf0faac3930cecdfdb082a3d7

I would be happy to add this to the generator. I found an unrelated previous issue regarding default search order with ES+MongoDB #8739

@oddiraju I added a pull request with your fix. This issue has a bug bounty tag on it. When it's merged you should claim it. The work was yours (i've just pasted it where needed). Cheers!

@ivangsa very nice of you to let @oddiraju get the bounty!!

-> I'm currently testing and merging this, it should be in today's release if everything goes well!

@ivangsa Thank you

Bounty paid to @oddiraju :-)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SudharakaP picture SudharakaP  ·  3Comments

frantzynicolas picture frantzynicolas  ·  3Comments

tomj0101 picture tomj0101  ·  3Comments

DanielFran picture DanielFran  ·  3Comments

chegola picture chegola  ·  4Comments