While using the entity interactive generator, and creating a many to one relationship to another entity
The process fails on ERROR! TypeError: Cannot read property 'toLowerCase' of undefined
Just a line after Everything is configured, generating the entity...
.
Generating this entity with same relationship from
Interactively generation entity with many-to-one relationship to another entity
Step 1
Welcome to JHipster v6.8.0
_______________________________________________________________________________________________________________
Documentation for creating an application is at https://www.jhipster.tech/creating-an-app/
If you find JHipster useful, consider sponsoring the project at https://opencollective.com/generator-jhipster
_______________________________________________________________________________________________________________
? Which *type* of application would you like to create? Monolithic application (recommended for simple projects)
? [Alpha] Do you want to make it reactive with Spring WebFlux? No
? What is the base name of your application? jhipster
? What is your default Java package name? com.norr.tr
? Do you want to use the JHipster Registry to configure, monitor and scale your application? No
? Which *type* of authentication would you like to use? JWT authentication (stateless, with a token)
? Which *type* of database would you like to use? SQL (H2, MySQL, MariaDB, PostgreSQL, Oracle, MSSQL)
? Which *production* database would you like to use? MySQL
? Which *development* database would you like to use? MySQL
? Do you want to use the Spring cache abstraction? Yes, with the Ehcache implementation (local cache, for a single node)
? Do you want to use Hibernate 2nd level cache? Yes
? Would you like to use Maven or Gradle for building the backend? Maven
? Which other technologies would you like to use? (Press <space> to select, <a> to toggle all, <i> to invert selection)
? Which *Framework* would you like to use for the client? Angular
? Would you like to use a Bootswatch theme (https://bootswatch.com/)? Default JHipster
? Would you like to enable internationalization support? No
? Besides JUnit and Jest, which testing frameworks would you like to use? (Press <space> to select, <a> to toggle all, <i> to invert selection)
? Would you like to install other generators from the JHipster Marketplace? No
Step 2
➜ final-rrr git:(master) jhipster entity author
INFO! Using JHipster version installed locally in current project's node_modules
INFO! Executing jhipster:entity author
INFO! Options: from-cli: true
The entity author is being created.
Generating field #1
? Do you want to add a field to your entity? Yes
? What is the name of your field? name
? What is the type of your field? String
? Do you want to add validation rules to your field? No
================= Author =================
Fields
name (String)
Generating field #2
? Do you want to add a field to your entity? No
================= Author =================
Fields
name (String)
Generating relationships to other entities
? Do you want to add a relationship to another entity? No
================= Author =================
Fields
name (String)
? Do you want to use separate service class for your business logic? Yes, generate a separate service class
? Do you want to use a Data Transfer Object (DTO)? No, use the entity directly
? Do you want to add filtering? Not needed
? Is this entity read-only? No
? Do you want pagination on your entity? Yes, with pagination links
Everything is configured, generating the entity...
create .jhipster/Author.json
create src/main/resources/config/liquibase/changelog/20200327222530_added_entity_Author.xml
create src/main/resources/config/liquibase/fake-data/author.csv
create src/main/java/com/norr/tr/domain/Author.java
create src/main/java/com/norr/tr/repository/AuthorRepository.java
create src/main/java/com/norr/tr/web/rest/AuthorResource.java
create src/main/java/com/norr/tr/service/AuthorService.java
create src/test/java/com/norr/tr/web/rest/AuthorResourceIT.java
create src/test/java/com/norr/tr/domain/AuthorTest.java
conflict src/main/resources/config/liquibase/master.xml
? Overwrite src/main/resources/config/liquibase/master.xml? overwrite this and all others
Step 3
➜ final-rrr git:(master) ✗ jhipster entity book
INFO! Using JHipster version installed locally in current project's node_modules
INFO! Executing jhipster:entity book
INFO! Options: from-cli: true
The entity book is being created.
Generating field #1
? Do you want to add a field to your entity? Yes
? What is the name of your field? title
? What is the type of your field? String
? Do you want to add validation rules to your field? No
================= Book =================
Fields
title (String)
Generating field #2
? Do you want to add a field to your entity? No
================= Book =================
Fields
title (String)
Generating relationships to other entities
? Do you want to add a relationship to another entity? Yes
? What is the name of the other entity? author
? What is the name of the relationship? author
? What is the type of the relationship? many-to-one
? When you display this relationship on client-side, which field from 'author' do you want to use? This field will be displayed as a String, so it cannot be a Blob name
? Do you want to add any validation rules to this relationship? No
================= Book =================
Fields
title (String)
Relationships
author (Author) many-to-one
Generating relationships to other entities
? Do you want to add a relationship to another entity? No
================= Book =================
Fields
title (String)
Relationships
author (Author) many-to-one
? Do you want to use separate service class for your business logic? Yes, generate a separate service class
? Do you want to use a Data Transfer Object (DTO)? No, use the entity directly
? Do you want to add filtering? Not needed
? Is this entity read-only? No
? Do you want pagination on your entity? Yes, with pagination links
Everything is configured, generating the entity...
ERROR! TypeError: Cannot read property 'toLowerCase' of undefined
Here after step 3 I'm getting the error
ERROR! TypeError: Cannot read property 'toLowerCase' of undefined
Jhipster 6.8.0
entityName.json
files generated in the .jhipster
directoryAuthor.json:
{
"fluentMethods": true,
"clientRootFolder": "",
"relationships": [],
"fields": [
{
"fieldName": "name",
"fieldType": "String"
}
],
"changelogDate": "20200327222530",
"dto": "no",
"searchEngine": false,
"service": "serviceClass",
"entityTableName": "author",
"databaseType": "sql",
"readOnly": false,
"jpaMetamodelFiltering": false,
"pagination": "pagination"
}
Operating system MacOS Catalina version 10.15.2
Hi, I've reproduced the issue. I'm going to dig into that
Actually i'm trying to debug it now, but i'm new to this project, can you guide me how to debug it ?
Yes, of course.
What I'm doing:
npm link
so that the cloned repo can be used everywhere (like npm i -g ...
 but for locally installed projects)npm link generator-jhipster
so that my previously linked project is used by the appThen, I'm gonna dig into the source code to try to find where the issue comes from.
It's actually tedious as there's no stacktrace (this is the worst, and it shouldn't happen --this is an issue itself and it should be fixed). So there's gonna be some trial/error from now, and it may involve a few console.log to find where the failure occurs
Ok I found the line causes the bug
https://github.com/jhipster/generator-jhipster/blob/add8f07d59c2967b28a4fbd07a6ab9b938774ee2/generators/entity/index.js#L945
This Issue is on "A unidirectional many-to-one relationship"
So there is no otherEntityRelationship
so relationship.otherEntityRelationshipName
is undefined
Nice! Couldn't find this needle in all haystack.
I think I now how to solve it one moment I'l send a PR
Alright, I'll see if importing a JDL content fails too
update: using a JDL content works fine
entity Author
entity Book
relationship ManyToOne {
Book{author} to Author
}
this should be the correct value of the relationships
attribute in the Book.json file:
"relationships": [
{
"relationshipType": "many-to-one",
"otherEntityName": "author",
"otherEntityRelationshipName": "book",
"relationshipName": "author",
"otherEntityField": "id"
}
],
Possibly related to #10984 and #11013
I'm going to sleep, I think @mshima would be interested to follow up on this issue (maybe @SudharakaP you can help too?). Anyway, @ramiloif thanks for the report and nice work :)
Good night
I have created a PR #11521 to solve it as a suggestion
It solved the problem for me.
I'm new so I hope the code makes sense.
The build failed on prettier so I'll fix that tomorrow.
Good night:)
@MathieuAA the bug is similar but to reduce this kind of bug just a complete refactoring =/.
I really want to do something for jhipster 7.
@ramiloif thanks for the patch, it makes sense.
But I think the correct fix is to remove the following lines:
https://github.com/jhipster/generator-jhipster/blob/add8f07d59c2967b28a4fbd07a6ab9b938774ee2/generators/entity/index.js#L385-L387
The field will be created at:
https://github.com/jhipster/generator-jhipster/blob/add8f07d59c2967b28a4fbd07a6ab9b938774ee2/generators/entity/index.js#L551
Once jhipster --with-entities
is executed the field will be created anyway, and can cause differences in the generated code.
@MathieuAA what do you think?
@ramiloif can you test if removing these lines fix the problem too?
https://github.com/jhipster/generator-jhipster/blob/add8f07d59c2967b28a4fbd07a6ab9b938774ee2/generators/entity/index.js#L385-L387
Yes removing the if also solved the issue
@ramiloif thanks.
Do you want to create another PR with this other approach?
So we can decide which one to merge?
Or both. It will make no harm :P.
I am inclined to merge both.
Yes I’ll create it...
Thanks @mshima for taking the time to look into that!
@mshima I have created the second PR #11523
Removing
@ramiloif can you test if removing these lines fix the problem too?
https://github.com/jhipster/generator-jhipster/blob/add8f07d59c2967b28a4fbd07a6ab9b938774ee2/generators/entity/index.js#L385-L387
@ramiloif first PR is merged
Second one we need to think about unidirectional vs bidirectional.
I'm adding a bounty on this as @MathieuAA you confirmed the issue
@pascalgrimaud its already fixed.
The missing problem is the reproducible problem.
If a subsequent jhipster —with-entities
is called the source can change.
But I didn’t confirmed it yet.
@pascalgrimaud do we support unidirectional relationships?
I think jdl always creates bidirectional. Am I right?
There are uni and bidirectional relationships, the JDL supports both as does JHipster. There are some cases where only bidirectional are supported though, and ways to generate relationships have full support.
@mshima : i'ts not a problem to put a bug bounty once the bug is fixed -> I'd like to put a bounty on each bug as it should be our priority. Then as @mshima @MathieuAA you follow closely the issue, you'll know who can claim it.
@ramiloif should claim it for know.
My doubt is if we should open a new issue for the other issue.
I will try to confirm it.
@mshima : yes don't hesitate to open another issue if this one is fixed and if it's a different one -> so it's clearer to follow and for another bounty if it's a bug :)
Closing this issue since it is fixed.
I will confirm the problem I am thinking about and if it's a bug.
How can I claim the bounty ?
@ramiloif I think this was your first contribution. So congrats.
Relevant links:
https://opencollective.com/generator-jhipster/expenses/new
https://www.jhipster.tech/bug-bounties/
Wow I’m very exited thanks a lot 😃
Most helpful comment
Wow I’m very exited thanks a lot 😃