Reputation: 165
I am using JHipster and I am at the point where the entities has to be set. I'm facing off an issue that doesn't allow me to generate an entity.
Basically I created a .jdl file and then I imported that on my JHipster project. The problem is that I am not able to generate all the entities. More in the specific the entity "Quiz".
Which could be the problem?
This is the log:
Error: ERROR! Copying template src/test/java/package/web/rest/_EntityResourceIntTest.java failed. [TypeError: /Users/manu/app/node_modules/generator-jhipster/generators/entity-server/templates/src/test/java/package/web/rest/_EntityResourceIntTest.java:199
197| private static final Integer <%=defaultValueName %> = <%= defaultValue %>;
198| private static final Integer <%=updatedValueName %> = <%= updatedValue %>;
>> 199| <%_ } else if (fieldType === 'Long') { _%>
200|
201| private static final Long <%=defaultValueName %> = <%= defaultValue %>L;
202| private static final Long <%=updatedValueName %> = <%= updatedValue %>L;
Cannot read property 'replace' of undefined]
at Environment.error (/Users/manu/app/node_modules/yeoman-environment/lib/environment.js:157:40)
at module.exports.error (/Users/manu/app/node_modules/generator-jhipster/generators/generator-base.js:2030:18)
at ejs.renderFile (/Users/manu/app/node_modules/generator-jhipster/generators/utils.js:193:23)
at tryHandleCache (/Users/manu/app/node_modules/ejs/lib/ejs.js:226:12)
at Object.exports.renderFile (/Users/manu/app/node_modules/ejs/lib/ejs.js:437:10)
at Object.renderContent (/Users/manu/app/node_modules/generator-jhipster/generators/utils.js:189:9)
at module.exports.template (/Users/manu/app/node_modules/generator-jhipster/generators/generator-base-private.js:528:23)
at blockTemplate.templates.forEach (/Users/manu/app/node_modules/generator-jhipster/generators/generator-base.js:2348:42)
at Array.forEach (<anonymous>)
at module.exports.writeFilesToDisk (/Users/manu/app/node_modules/generator-jhipster/generators/generator-base.js:2325:45)
This is the .jdl file's part where Quiz is used.
entity Position {
positionId Integer,
description String,
domain String,
status String,
createdBy String,
createdOn LocalDate,
quizId Integer
}
entity Quiz {
quizId Integer,
quizName String,
startDate LocalDate,
endDate LocalDate,
status String,
marks String
questionsNumber Integer,
questions String[],
complexity String
}
entity Question {
questionId Integer,
section String,
description String,
optionA String,
optionB String,
optionC String,
optionD String,
answer String,
marks String,
status String,
complexity String,
quizId Integer
}
entity Result {
resultId Integer,
obtainedMarks String,
percentage Double,
appearedOn String,
quizId Integer,
customUserId Integer
}
relationship OneToMany {
Position{quizId} to Quiz{quizId}
}
relationship OneToOne {
Quiz{quizId} to Result{quizId}
}
relationship ManyToOne {
Question{quizId} to Quiz{quizId}
}
All the entities goes well except "Quiz", I don't know why. Could someone please spend some time to help me? I would be happy for this, I don't know how to solve this.
Upvotes: 0
Views: 2015
Reputation: 10716
The entity generator most probably fails upon reaching the part where you declare relationships. The field you put in {}
is supposed to be of the relationship target type and not an Integer
.
For example, if the following piece of code:
relationship OneToMany {
Position{quiz} to Quiz
}
means that you want JHipster to create a field named quiz
in Position
which will be of the type Quiz
. Also, you're not supposed to declare the fields both in the relationship
and the entity
sections. Above all, you don't need any id
fields as these are added by JHipster to all entities by default.
Simply remove all the quizId
fields from your entity declarations. JHipster will create the fields corresponding to relationships between entities, using the information provided in the relationship
blocks. You might want to rename the fields used in relationship
blocks, since they will end up being the actual referenced objects (and not their ids).
Upvotes: 2