Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neo4J: Cyclic OneToMany adds an incorrect ManyToOne #11691

Open
jkransen opened this issue May 3, 2020 · 2 comments
Open

Neo4J: Cyclic OneToMany adds an incorrect ManyToOne #11691

jkransen opened this issue May 3, 2020 · 2 comments

Comments

@jkransen
Copy link

@jkransen jkransen commented May 3, 2020

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:
#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)
@atomfrede
Copy link
Member

@atomfrede atomfrede commented May 3, 2020

Thanks @jkransen for reporting this and being brave using the neo4j support. Just to make sure, the generated entity contains both the Set<Person> and the backreference to Person? Indeed that looks like a bug as it should not be needed with neo. I will try to have look.

@jkransen
Copy link
Author

@jkransen jkransen commented May 3, 2020

Hi @atomfrede , indeed I want to give Neo4J a try. At least I can learn something about it along the way. I will be glad to give more feedback knowing that it will be picked up. Maybe a few small steps on the road to get rid of that beta tag :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.