Search code examples
hibernatejhipsterjdl

Jhipster JDL relationships. Relation between two entities, Entity A is one to many with two columns seperately in entity B


Entity A: Person, Entity B: Payment (columns: effectiveDate, fromPerson, toPerson). Person should be one to many with both fromPerson and to Person so that I can track payer and payee.

This is how I have defined them in jdl file which is not working as desired.

entity Person {
  firstName String maxlength(100)
  lastName String maxlength(100)
}
entity Payment{
  effectiveDate Instant
  paymentRefNumber String
  amount Double
}

relationship OneToMany {
  Person to Payment{fromParty}
  Person to Payment{toParty}
}

When I generate code with this jdl file, I am getting error in person pojos where the relationships are defined twice and when I rectify them, application is taking too long to start about 30 mins

Any idea where I am going wrong?

My jdl file configuration:

application {
  config {
    databaseType sql
    devDatabaseType postgresql
    enableHibernateCache true
    enableSwaggerCodegen false
    enableTranslation true
    jhiPrefix sys
    languages [en, bn, hi, mr, ta, te]
    nativeLanguage en
    packageName com.eezibizi
    prodDatabaseType postgresql
    serviceDiscoveryType false
    skipClient false
    skipServer false
    testFrameworks [gatling, cucumber, protractor]
    websocket spring-websocket
    applicationType monolith
    baseName eezibizi
    serverPort 8080
    authenticationType session
    cacheProvider hazelcast
    buildTool gradle
    useSass true
    clientPackageManager npm
    clientFramework react
  }
  entities *
}

If there is a better approach, please suggest


Solution

  • The problem is that you have two relationships from Person to Payment but you did not specify a relationship name for any of them. The default name will be used for both (payments I guess) leaving you with two fields having the same name, and this is incorrect for obvious reasons.

    Give them names and everything should be generated correctly.

    relationship OneToMany {
      Person{outgoingPayments} to Payment{fromPerson}
      Person{incomingPayments} to Payment{toPerson}
    }