The otherEntityRelationshipNamePlural field is not correctly filled
It makes the generation of ManyToOne relationships incorrect when the relationship name is different than the other entity name
Employee.java the relationship to Company should be annotated with @JsonIgnoreProperties("awesomeEmployees"). Instead we get @JsonIgnoreProperties("employees") Welcome to the JHipster Information Sub-Generator
[email protected] /home/cbornet/workspace/jhipsterapps/test
└── [email protected]
##### **JHipster configuration, a `.yo-rc.json` file generated in the root folder**
{
"generator-jhipster": {
"promptValues": {
"packageName": "com.mycompany.myapp",
"nativeLanguage": "en"
},
"jhipsterVersion": "6.5.1",
"applicationType": "monolith",
"baseName": "test",
"packageName": "com.mycompany.myapp",
"packageFolder": "com/mycompany/myapp",
"serverPort": "8080",
"authenticationType": "jwt",
"cacheProvider": "ehcache",
"enableHibernateCache": true,
"websocket": false,
"databaseType": "sql",
"devDatabaseType": "h2Disk",
"prodDatabaseType": "mysql",
"searchEngine": false,
"messageBroker": false,
"serviceDiscoveryType": false,
"buildTool": "maven",
"enableSwaggerCodegen": false,
"jwtSecretKey": "bXktc2VjcmV0LXRva2VuLXRvLWNoYW5nZS1pbi1wcm9kdWN0aW9uLWFuZC10by1rZWVwLWluLWEtc2VjdXJlLXBsYWNl",
"embeddableLaunchScript": false,
"useSass": true,
"clientPackageManager": "npm",
"skipClient": true,
"creationTimestamp": 1576676291495,
"testFrameworks": [],
"jhiPrefix": "jhi",
"entitySuffix": "",
"dtoSuffix": "DTO",
"otherModules": [],
"enableTranslation": true,
"nativeLanguage": "en",
"languages": [
"en"
],
"blueprints": []
}
}
entityName.json files generated in the .jhipster directory
JDL entity definitions
entity Company
entity Employee
relationship OneToMany {
Company{awesomeEmployee} to Employee{company}
}
service Company, Employee with serviceImpl
openjdk version "11.0.4" 2019-07-16
OpenJDK Runtime Environment (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3)
OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3, mixed mode, sharing)
git version 2.17.1
node: v10.14.1
npm: 6.9.0
yeoman: 3.1.1
yarn: 1.9.4
Docker version 18.06.1-ce, build e68fc7a
docker-compose version 1.17.1, build unknown
@cbornet : I gave this a try with your exact .yo-rc.json and the JDL file and for me it worked correctly. The generated Employee.java file is as follows;
package com.mycompany.myapp.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import javax.persistence.*;
import java.io.Serializable;
/**
* A Employee.
*/
@Entity
@Table(name = "employee")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JsonIgnoreProperties("awesomeEmployees")
private Company company;
// jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Company getCompany() {
return company;
}
public Employee company(Company company) {
this.company = company;
return this;
}
public void setCompany(Company company) {
this.company = company;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Employee)) {
return false;
}
return id != null && id.equals(((Employee) o).id);
}
@Override
public int hashCode() {
return 31;
}
@Override
public String toString() {
return "Employee{" +
"id=" + getId() +
"}";
}
}
Is there some other step I am missing in order to reproduce this error? :thinking:
Same than @SudharakaP
I didn't manage to reproduce, I have the same result
Oh I get it ! That's because I generated the entities with the CLI and not with the JDL.
It doesn't generate otherEntityRelationshipName in Employee.json and I was not asked about it during the questions.
Actually the manual generation works. The problem occurs when regenerating with jhipster --with-entities
To reproduce:
jhipster entity Company
The entity Company is being created.
Generating field #1
? Do you want to add a field to your entity? No
Generating relationships to other entities
? Do you want to add a relationship to another entity? Yes
? What is the name of the other entity? Employee
? What is the name of the relationship? awesomeEmployee
? What is the type of the relationship? one-to-many
? What is the name of this relationship in the other entity? company
================= Company =================
Relationships
awesomeEmployee (Employee) one-to-many
Generating relationships to other entities
? Do you want to add a relationship to another entity? No
================= Company =================
Relationships
awesomeEmployee (Employee) one-to-many
? Do you want to use separate service class for your business logic? No, the REST controller should use the repository directly
? Is this entity read-only? No
? Do you want pagination on your entity? No
Everything is configured, generating the entity...
jhipster entity Employee
The entity Employee is being created.
Generating field #1
? Do you want to add a field to your entity? No
Generating relationships to other entities
? Do you want to add a relationship to another entity? Yes
? What is the name of the other entity? Company
? What is the name of the relationship? company
? What is the type of the relationship? many-to-one
? When you display this relationship on client-side, which field from 'Company' do you want to use? This field will be displayed as a String, so it cannot be a Blob id
? Do you want to add any validation rules to this relationship? No
================= Employee =================
Relationships
company (Company) many-to-one
Generating relationships to other entities
? Do you want to add a relationship to another entity? No
================= Employee =================
Relationships
company (Company) many-to-one
? Do you want to use separate service class for your business logic? No, the REST controller should use the repository directly
? Is this entity read-only? No
? Do you want pagination on your entity? No
Everything is configured, generating the entity...
jhipster --with-entities
Just tried to reproduce and I think you're right @cbornet
See the generated JSON:
➜ cat .jhipster/Employee.json
{
"fluentMethods": true,
"clientRootFolder": "",
"relationships": [
{
"relationshipName": "company",
"otherEntityName": "company",
"relationshipType": "many-to-one",
"otherEntityField": "id"
}
],
"fields": [],
"changelogDate": "20191220085629",
"dto": "no",
"searchEngine": false,
"service": "no",
"entityTableName": "employee",
"databaseType": "sql",
"readOnly": false,
"jpaMetamodelFiltering": false,
"pagination": "no"
}
We can see the missing: "otherEntityRelationshipName": "awesomeEmployee", in Employe.json
But in fact, in the workflow when using jhipster entity Employee, there is no question about What is the name of the relationship
I'm not an expert on this part, so I don't know what should be the correct behavior.
Maybe you can help @MathieuAA ?
It seems OK when generating the entity the first time though. I think the generator loads the Company entity and correctly gets/sets the otherEntityRelationshipName.
The problem is that it doesn't do it when regenerating with --with-entities
@cbornet : yes, I reproduce all your steps and I confirm exactly what you found
Just a suggestion, maybe we should save this value inside the Employee.json I think: "otherEntityRelationshipName": "awesomeEmployee"
Indeed. That's what the JDL import does.
Adding a bounty on this, as it's a bug and it needs to be fixed !
I think I found the problem.
Creating a PR.
PR #11008 fix this specific problem.
I will create another PR with a follow up, that maybe should be wait for 6.6.1.
Tried the fix provided by @mshima
And it fixed the issue. At least, I didn't manage to reproduce anymore