我有典型的模型:Employee及其子类RegularEmployee和ContractEmployee
我该如何在 jhipster 中处理这个问题? 我在hibernate上做了一个JOINED继承策略。这是理所当然的。但我无法让 jhipster 将 RegularEmployee 实例保存到数据库中。
最佳答案
嗯,显然比我想象的要容易。
使用 InheritanceStrategy.JOINED 的示例
第一步
生成三个类 Employee 及其子类 RegularEmployee 和 ContractEmployee,就好像它们是单独的类一样,异常(exception),因为您不会在子类上重复继承的属性。
第二步
在 Employee 类上添加注释,告诉 hibernate 它将成为父类(super class) you can find how to do that here
删除 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
第三步
将extends Employee添加到java子类中。
第四步
这里你应该能够在 Angular 上使用 $scope 继承,但我对此很陌生,所以我不知道如何在 jhipster 使用的应用程序结构上执行此操作 如果有人告诉我如何改进这一点,我将不胜感激
在您的contractEmployee-dialog.html和regularEmployee-dialog.html上添加从Employee继承的字段,以便您可以生成一个可以正确保存的模型hibernate,否则你会得到验证错误。
第五步
构建并测试。
关于angularjs - 在 jhipster 实体上使用继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33334746/