简体   繁体   English

Jhipster实体生成错误

[英]Jhipster Entity Generation Error

I am using JHipster and I am at the point where the entities has to be set. 我正在使用JHipster,并且必须要设置实体。 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. 基本上,我创建了一个.jdl文件,然后将其导入到我的JHipster项目中。 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. 这是.jdl文件中使用测验的部分。

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. 我为此感到高兴,但我不知道该如何解决。

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 . 您在{}的字段应该是关系目标类型,而不是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 . 表示您希望JHipster在Position创建一个名为quiz的字段,该字段的类型为Quiz Also, you're not supposed to declare the fields both in the relationship and the entity sections. 另外,您不应在relationshipentity部分中都声明字段。 Above all, you don't need any id fields as these are added by JHipster to all entities by default. 最重要的是,您不需要任何id字段,因为JHipster默认将它们添加到所有实体。

Simply remove all the quizId fields from your entity declarations. 只需从实体声明中删除所有quizId字段即可。 JHipster will create the fields corresponding to relationships between entities, using the information provided in the relationship blocks. JHipster将使用relationship块中提供的信息来创建与实体之间的关系相对应的字段。 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). 您可能想重命名relationship块中使用的字段,因为它们最终将成为实际引用的对象(而不是其ID)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM