在jhipster实体上使用继承

Pac*_*acu 9 hibernate angularjs jhipster

我有典型的模型:Employee和它的子类RegularEmployee和ContractEmployee

典型的模型

我如何在jhipster中处理这个问题? 我在hibernate上做了一个JOINED继承策略.那简直太难了.但我无法让jhipster将RegularEmployee实例保存到数据库中.

Pac*_*acu 9

好吧,显然比我想象的容易.

使用InheritanceStrategy.JOINED的示例

第一步

生成你的三个类Employee,它的子类是RegularEmployee和ContractEmployee,就像它们是单独的类一样,除了你不会在子类上重复继承的属性这一事实.

第二步

在Employee类上添加注释告诉hibernate它将成为超级类,你可以在这里找到如何做到这一点

删除 id生成类型注释,因为您的子类实例具有与其父实例相同的ID.

@Id // this should be gone
@GeneratedValue(strategy = GenerationType.AUTO) // this should be gone
@Column(name="id")// this should be gone
private Long id;// this should be gone
Run Code Online (Sandbox Code Playgroud)

第三步

扩展的Employee添加到java 子类中.

第四步

在这里你应该能够在角度上使用$ scope继承,但我是新手,所以我不知道如何在jhipster使用的app结构上做到这一点 如果有人告诉我如何改进我将不胜感激这个

在您的contractEmployee-dialog.htmlregularEmployee-dialog.html上添加Employee的继承字段,这样您就可以生成一个可以通过hibernate正确保存的模型,否则您将收到验证错误.

第五步

构建和测试.

  • 如果我使用 jdl-studio 更新 `Regular_Employee` 会发生什么?我会丢失手动更新吗? (2认同)