Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using inheritance on jhipster entities

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.

like image 422
Pacu Avatar asked Oct 25 '15 20:10

Pacu


People also ask

How to generate entity using JHipster?

You can generate entities from a JDL file using the jdl sub-generator, by running jhipster jdl your-jdl-file. jh . If you do not want to regenerate your entities, while importing a JDL, you can use the --json-only flag to skip entity creation part and create only the json files in .

How to update entity in JHipster?

Upgrade JHipster to the latest available version globally. Clean the current project directory. Re-generate the application using the jhipster --force --with-entities command. Commit the generated code to the jhipster_upgrade branch.

How do you create a many to many relationship in JHipster?

If you want to create many entities and relationships, you might prefer to use a graphical tool. In that case, two options are available: JHipster UML, which allows you to use an UML editor. JDL Studio, our online tool to create entities and relationships using our domain-specific language.

What is JDL JHipster?

The JDL is a JHipster-specific domain language where you can describe all your applications, deployments, entities and their relationships in a single file (or more than one) with a user-friendly syntax.


1 Answers

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.

like image 197
Pacu Avatar answered Oct 12 '22 02:10

Pacu