在jhipster实体上使用继承

时间:2015-10-25 20:29:54

标签: angularjs hibernate jhipster

我有典型的模型:员工及其子类RegularEmployee和ContractEmployee

the typical model

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

1 个答案:

答案 0 :(得分:8)

嗯,显然比我想象的容易。

使用InheritanceStrategy.JOINED

的示例

第一步

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

第二步

在Employee类上添加注释告诉hibernate它将成为超类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 子类

第四步

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

,我将不胜感激 contractEmployee-dialog.html regularEmployee-dialog.html 上的

添加来自Employee的继承字段,以便您可以生成可以正确保存的模型休眠,否则你会得到验证错误。

第五步

构建和测试。