Some of our data entities have more than one collection of child entities with the same data type. Here is a JDL file to illustrate the relationship.
entity Parent {
name String
headOfHousehold Boolean
}
entity Child {
name String
}
relationship ManyToOne {
Child{parent(name)} to Parent{boys}
Child{parent(name)} to Parent{girls}
}
When I run the import command, I get the following error:
Error: Error at entity Parent: relationship name is not synchronized {
"otherEntityName": "child",
"otherEntityRelationshipName": "parent",
"relationshipName": "girls",
"relationshipType": "one-to-many",
"otherEntity": "[Child Entity]",
"otherEntityField": "id",
"ownerSide": false,
"collection": true,
"otherSideReferenceExists": false,
"otherEntityIsEmbedded": false
} with {
"otherEntityField": "name",
"otherEntityName": "parent",
"otherEntityRelationshipName": "boys",
"relationshipName": "parent",
"relationshipType": "many-to-one",
"otherEntity": "[Parent Entity]"
}
I don't know what "synchronized" means in the message.
After renaming the Child entity,
entity Parent {
name String
headOfHousehold Boolean
}
entity Boy {
name String
}
entity Girl {
name String
}
relationship ManyToOne {
Boy{parent(name)} to Parent{boys}
Girl{parent(name)} to Parent{girls}
}
The import process will work without the error.
In JPA, the following entity class structure is correct.
@Entity
public class Parent {
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "parent_id")
private Collection<Child> boys;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "parent_id")
private Collection<Child> girls;
}
@Entity
public class Child {
// ...
}
Why JHipster doesn't work for the same entity class structure?
The issue isn't about duplicating types, but duplicating names.
You named the relationship parent
in both cases and they are in the same Child class. Using boysParent
and girlsParent
would have worked:
relationship ManyToOne {
Child{boysParent(name)} to Parent{boys}
Child{girlsParent(name)} to Parent{girls}
}
Have a look at the documentation: https://www.jhipster.tech/managing-relationships/#two-one-to-many-relationships-on-the-same-two-entities