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

微服务架构下JHipster实体关系无法保存的技术求助

微服务架构下JHipster实体关系保存失效问题

问题表现

  • 从单体架构转为微服务后,实体关系无法成功保存:Web应用编辑实体后前端提示操作成功,但刷新页面或查看数据库时,变更并未生效,无任何实际操作结果
  • 网关和微服务日志中未出现任何错误或警告信息
  • PUT更新请求中确实包含选中的从属实体数据:
organisation: {
    "id": "f43d61b1-3ba5-4891-a252-a5e0d73e4bbc",
    "name": "Nevada Wooden Principal",
    "status": "synergize transmit Hybrid",
    "location": "interactive incremental",
    "headcount": 7182,
    "parent": {
        "id": null,
        "name": null,
        "status": null,
        "location": null,
        "headcount": null,
        "parentId": null
    },
    "parentId": null
}
organisationId: null,
personalInfo: {
    "id": "0b76be08-4cbf-408d-ab03-3ba9a3add15d",
    "dateOfBirth": "2023-07-11",
    "network": "Bicycle Uranium Integration",
    "wallet": null
},
personalInfoId: null

但查询主实体的GET请求返回结果中,关系字段全为null:

organisation: {
    "id": null,
    "name": null,
    "status": null,
    "location": null,
    "headcount": null,
    "parentId": null
},
organisationId: null,
personalInfo: {
    "id": null,
    "dateOfBirth": null,
    "network": null,
    "wallet": null
}
personalInfoId: null

已尝试的排查动作

  • 测试过JHipster 7.9.3、v7.x_maintenance、8.0.0-beta.1及main分支最新版本,未发现同类BUG上报,推测问题出在自身配置/操作上
  • 单体架构中曾通过为所有实体统一定义UUID类型ID解决关系保存问题,微服务架构下已尝试此方法,同时也试过依赖默认ID配置
  • 为适配JHipster 8.0版本,已将默认的JWT认证改为OAuth2,客户端框架从Vue改为React

简化后的JDL配置

application {
  config {
    applicationType gateway
    authenticationType oauth2
    baseName mynk
    buildTool gradle
    clientFramework react
    clientTheme zephyr
    devDatabaseType h2Memory
    languages [en, fr]
    nativeLanguage en
    packageName ma.mynk.wallet
    prodDatabaseType postgresql
    serviceDiscoveryType consul
  }
  entities *
}

application {
  config {
    applicationType microservice
    authenticationType oauth2
    baseName walletService
    buildTool gradle
    devDatabaseType h2Memory
    packageName ma.mynk.wallet.core
    prodDatabaseType postgresql
    serviceDiscoveryType consul
  }
  entities *
}

entity Wallet {
  id UUID
  phoneNumber String
  tag String 
  firstName String 
  lastName String 
  email String
  currency String 
  contractId String 
}

entity PersonalInfo {
  id UUID
  dateOfBirth LocalDate
  network String
}

entity Organisation {
  id UUID
  name String 
  status String 
  location String 
  headcount Integer
}

relationship OneToOne {
  Wallet{personalInfo} to PersonalInfo
}

relationship ManyToOne {
  Organisation{parent(name)} to Organisation
  Wallet{organisation(name)} to Organisation
}

service * with serviceImpl
paginate * with pagination

应用生成与运行步骤

  • 生成命令:
    jhipster jdl --skip-jhipster-dependencies --workspaces --monorepository ../docs/jdl/relationship.jdl
    
  • 启动依赖服务:
    docker compose -f src/main/docker/consul.yml up -d
    docker compose -f src/main/docker/keycloak.yml up -d
    
  • 启动微服务:在每个微服务目录下执行./gradlew

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 10:12:17