在 jhipster 实体上使用继承
Using inheritance on jhipster entities
我有典型的模型:Employee 及其子类 RegularEmployee 和 ContractEmployee
我如何在 jhipster 中处理这个问题?
我在hibernate上做了一个JOINED继承策略。那是没有道理的。但是我无法让 jhipster 将 RegularEmployee 实例保存到数据库中。
好吧,显然比我想象的要容易。
示例使用 InheritanceStrategy.JOINED
第一步
生成三个 classes Employee 及其子classes RegularEmployee 和 ContractEmployee 就好像它们是分开的 classes,except因为您不会在 subclasses.
上重复继承的属性
第二步
在 Employee class 上添加注解以告诉 hibernate 它将成为超级 class you can find how to do that here
删除 ID 生成类型注释,因为您的子classes 实例与其父实例具有相同的 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 subclasses.
第四步
这里你应该可以在angular上使用$scope继承,但我是新手,所以我不知道如何在应用程序结构上做jhipster 使用 如果有人告诉我如何改进它我将不胜感激
在您的 contractEmployee-dialog.html 和 regularEmployee-dialog.html 添加从 Employee 继承的字段,所以你可以生成一个可以被hibernate正确保存的模型,否则你会得到验证错误。
第五步
构建并测试。
我有典型的模型:Employee 及其子类 RegularEmployee 和 ContractEmployee
我如何在 jhipster 中处理这个问题? 我在hibernate上做了一个JOINED继承策略。那是没有道理的。但是我无法让 jhipster 将 RegularEmployee 实例保存到数据库中。
好吧,显然比我想象的要容易。
示例使用 InheritanceStrategy.JOINED
第一步
生成三个 classes Employee 及其子classes RegularEmployee 和 ContractEmployee 就好像它们是分开的 classes,except因为您不会在 subclasses.
上重复继承的属性第二步
在 Employee class 上添加注解以告诉 hibernate 它将成为超级 class you can find how to do that here
删除 ID 生成类型注释,因为您的子classes 实例与其父实例具有相同的 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 subclasses.
第四步
这里你应该可以在angular上使用$scope继承,但我是新手,所以我不知道如何在应用程序结构上做jhipster 使用 如果有人告诉我如何改进它我将不胜感激
在您的 contractEmployee-dialog.html 和 regularEmployee-dialog.html 添加从 Employee 继承的字段,所以你可以生成一个可以被hibernate正确保存的模型,否则你会得到验证错误。
第五步
构建并测试。