11

I have the typical model: Employee and it's subclasses RegularEmployee and ContractEmployee

the typical model

how can I deal with this in jhipster? I did a JOINED inheritance strategy on hibernate. that was a no brainer. But I can't get jhipster to save the RegularEmployee instance to the database.

Pacu
  • 1,985
  • 20
  • 33

1 Answers1

10

Well, apparently was easier than I thought.

Example using InheritanceStrategy.JOINED

First Step

generate your three classes Employee and it's subclasses RegularEmployee and ContractEmployee as if they were separate classes, except for the fact that you won't be repeating the inherited attributes on the subclasses.

Second Step

Add the annotations on the Employee class to tell hibernate that it's going to be the super class you can find how to do that here

REMOVE the id generation type annotations because your subclasses instances to have the same ID as their parent instance.

@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

Third Step

add the extends Employee to the java subclasses.

Fourth Step

here you should be able to use $scope inheritance on angular, but I'm new to it, so I don't know how to do it on the app structure that jhipster uses I'll be grateful if someone tells me how to improve this

on your contractEmployee-dialog.html and regularEmployee-dialog.html add the inherited fields from Employee, so that you can generate a Model that can be saved properly by hibernate, otherwise you will get validation errors.

Fifth Step

Build and test.

Pacu
  • 1,985
  • 20
  • 33
  • 2
    What happens if I update `Regular_Employee` using jdl-studio? Do I lose my manual updates? – Halil Apr 04 '17 at 07:40
  • I haven't used JDL-Studio in quite a while but, my guess would be that on the code generation phase you will have some conflicts which you will have to solve yourself. – Pacu Apr 05 '17 at 14:19
  • 1
    The domain language does not yet support it https://www.jhipster.tech/jdl/ – Nick Jun 23 '19 at 01:08