You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JHipster在线生成项目缺失Model.jdl及权限枚举扩展咨询

JHipster JDL File Missing & Authority Enum Questions

Let’s tackle your questions one by one:

1. Why is src/model/Model.jdl missing when using the online generator?

The Eclipse JHipster plugin generates and stores the JDL file locally as part of its workflow—it keeps the JDL tied directly to your project for easy updates later.

On the other hand, the online generator’s default workflow converts your configuration choices directly into project code without including the raw JDL file in the downloaded zip. But you can get the JDL file easily:

  • Before generating the app, use the "Design your JDL" tab to build your model, then export the JDL (look for the export button)
  • Or, after configuring your app in the online generator, check the "Advanced" section for an option to download the corresponding JDL file alongside the project zip.

2. JDL Code for User & Authority

Here’s a standard JDL snippet that defines the User and Authority entities with their typical relationship:

enum AuthorityName {
    ROLE_USER,
    ROLE_ADMIN
}

entity Authority {
    name AuthorityName required unique
}

entity User {
    login String required unique,
    password String required,
    firstName String,
    lastName String,
    email String required unique,
    activated Boolean required,
    langKey String,
    imageUrl String,
    activationKey String,
    resetKey String,
    resetDate Instant
}

relationship ManyToMany {
    User{authority(name)} to Authority{user(login)}
}

// Add JHipster's standard settings for core entities
service Authority with serviceClass
service User with serviceClass
dto Authority with mapstruct
dto User with mapstruct

3. Is authority.name an enum? How to add more values?

Yes, authority.name is almost always defined as an enum in JHipster projects (as shown in the JDL above)—this ensures role consistency across your app.

To add more enum values:

  1. If you’re using JDL (recommended):

    • Edit your JDL file’s AuthorityName enum to include new roles, e.g.:
      enum AuthorityName {
          ROLE_USER,
          ROLE_ADMIN,
          ROLE_MODERATOR, // New role
          ROLE_GUEST      // New role
      }
      
    • Run the command jhipster import-jdl your-model.jdl in your project root—this will update the enum class, database schema, and any related code automatically.
  2. If you’ve already generated the project without JDL:

    • Locate the AuthorityName enum class (usually in src/main/java/[your-package]/domain/enumeration/AuthorityName.java)
    • Add your new enum values directly in the class, e.g.:
      public enum AuthorityName {
          ROLE_USER,
          ROLE_ADMIN,
          ROLE_MODERATOR,
          ROLE_GUEST
      }
      
    • Don’t forget to update your database (if using JPA) to reflect the new allowed values—you can generate a Liquibase/Flyway migration script for this change.

内容的提问来源于stack exchange,提问作者Jeya Balaji

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:11:31