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.

Neo4J: Cyclic OneToMany adds an incorrect ManyToOne

See original GitHub issue
Overview of the issue

Neo4J generation Cyclic Relationship to entity itself results in second, incorrect property.

Motivation for or Use Case

I want a Person to have friends as a collection of type Person.

Reproduce the error
entity Person {
   name: String
}

relationship OneToMany {
   Person{friends} to Person
}

Generate application based on this. Generated domain class:

@Node
public class Person implements Serializable {

    // correct: 

    @Relationship
    private Set<Person> friends = new HashSet<>();

    // incorrect:

    @Relationship("person")
    @JsonIgnoreProperties("friends")
     private Person person;

}

Also, some additional code is generated based on this, including CRUD in the front end.

Related issues

This similar issue was related to React, and Neo4J was not used back then: https://github.com/jhipster/generator-jhipster/issues/11549

Suggest a Fix

Do not generate the reverse relationship in a OneToMany to type itself for Neo4J.

JHipster Version(s)

6.8.0

JHipster configuration

{ “generator-jhipster”: { “promptValues”: { “packageName”: “com.blabla”, “nativeLanguage”: “en” }, “jhipsterVersion”: “6.8.0”, “applicationType”: “monolith”, “baseName”: “blabla”, “packageName”: “com.blabla”, “packageFolder”: “com/blabla”, “serverPort”: “8080”, “authenticationType”: “jwt”, “cacheProvider”: “ehcache”, “enableHibernateCache”: false, “websocket”: false, “databaseType”: “neo4j”, “devDatabaseType”: “neo4j”, “prodDatabaseType”: “neo4j”, “searchEngine”: false, “messageBroker”: false, “serviceDiscoveryType”: false, “buildTool”: “maven”, “enableSwaggerCodegen”: false, “jwtSecretKey”: “”, “embeddableLaunchScript”: false, “useSass”: true, “clientPackageManager”: “npm”, “clientFramework”: “angularX”, “clientTheme”: “minty”, “clientThemeVariant”: “primary”, “creationTimestamp”: 1588343391509, “testFrameworks”: [“cucumber”], “jhiPrefix”: “jhi”, “entitySuffix”: “”, “dtoSuffix”: “DTO”, “otherModules”: [], “enableTranslation”: true, “nativeLanguage”: “en”, “languages”: [“en”], “blueprints”: [], “herokuAppName”: “blabla”, “herokuDeployType”: “jar” } }

If you have a JDL please wrap it in below structure

JDL definitions
     JDL content here
  
-->
Entity configuration(s) entityName.json files generated in the .jhipster directory

Here, Person is called Trainer. I think I already see the problem. There is a ManyToOne after the OneToMany that should probably go. I checked, and it is not in the jhipster-jdl.jh

{ “name”: “Trainer”, “fields”: [ { “fieldName”: “name”, “fieldType”: “String” }, { “fieldName”: “code”, “fieldType”: “Long” }, { “fieldName”: “level”, “fieldType”: “Integer” }, { “fieldName”: “xp”, “fieldType”: “Integer” }, { “fieldName”: “team”, “fieldType”: “Team”, “fieldValues”: “VALOR,MYSTIC,INSTINCT” } ], “relationships”: [ { “relationshipType”: “one-to-many”, “otherEntityName”: “trainer”, “otherEntityRelationshipName”: “trainer”, “relationshipName”: “friends” }, { “relationshipType”: “many-to-one”, “otherEntityName”: “trainer”, “otherEntityRelationshipName”: “friends”, “relationshipName”: “trainer”, “otherEntityField”: “id” } ], “changelogDate”: “20200502070200”, “entityTableName”: “trainer”, “dto”: “no”, “pagination”: “no”, “service”: “serviceImpl”, “jpaMetamodelFiltering”: false, “fluentMethods”: true, “readOnly”: false, “embedded”: false, “clientRootFolder”: “”, “applications”: “*” }

Browsers and Operating System

Linux Mint 19

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
atomfredecommented, Sep 11, 2020

Does it cause any problems except for neo4j? If not let’s just do it for neo

0reactions
MathieuAAcommented, Sep 10, 2020

@atomfrede should we disable the automatic conversion to a bidirectional one-to-many relationship only if the DB type is Neo4j? Or also if the source & destination entities are the same?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved: Logical cyclic mapping dependency - Neo4j - 46015
The problem is rooted in the dependency chain (cycle) Tree -> Person -> Tree , as you have already discovered. Spring Data Neo4j...
Read more >
Why bi-directional ManyToOne causes circular dependency in ...
You have two solutions : Use @JsonIgnore on the @ManyToOne; Do NOT serialize your entities. Use DTOs instead and take care while mapping...
Read more >
Three clases where one is bidirectional with other two make ...
Coding example for the question Three clases where one is bidirectional with other two make circular dependency-Springboot.
Read more >
Hibernate OGM 5.4.1.Final: Reference Guide
Hibernate OGM is a persistence engine providing Java Persistence (JPA) support for NoSQL datastores. It reuses Hibernate ORM's object life ...
Read more >
Spring jpa save parent and child together
How are initialization and destroy life cycle methods used. ... AUTO) private Long id; @OneToMany ( mappedBy = "parent", cascade = CascadeType. 17....
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