I'm new to Jhipster and I'm trying to understand how Jhipster entity generator work.
I'm trying create 3 simple class: Person, Professor, Student. I created a first entity (Person) and then I would like to create a second one (Professor) and make it extend to the first one but it's not proposed.
How to make the "professor" extends to "Person"? Am I suppose to do it directly on the code or did I miss something somewhere?
As per the docs https://www.jhipster.tech/jhipster-uml/ inheritance is not yet possible by jhipster entity generator yet.
But you can do it manually once entity generator generates the entities.
See this too.
https://github.com/jhipster/jhipster-uml/issues/96
jhipster generates entities not only as classes (spring beans), but also for everything else in the "jhipster-construct": Spring security, relationships, database layout incl. liquibase database refactoring, services, repositories, DTOs, the frontend components with Angular or React, validation and integration and performance tests for back- and frontend. And all in a "best-practice"-manner, with i18n related stuff etc., including two stages, a development and a production profile (with a database for each stage). Additionally, jhipster provides you with all the configuration to deploy contionuously to e.g. heroku with jenkins controlling your git pushes.
To build abstract (java) classes or (java) interfaces isn't possible this way. That may make sense in some business logic, which is to be implemented after generation or there may be other ways than inheritance (e.g. see services and dtos).
The jhipster-generated construct for backend and frontend - or even for microservices and gateways - shows the paths to stay on.
You can manage a lot of things that persons and professors share with OneToOne- or OneToMany-relationships between them and/or additional entities by thinking of database normalization - at least, I have done it this way :-)
Related
I am designing the architecture of my new app.I chose microservice architecture.In my architecture I noticed that I have models that are used by diffrent microservices. I want to know if there is a way to share models code between microservices instaed of writing them in each microservice.
By the way I am using the spring boot framework for my app.
You should only be sharing models that define the API of your micro-service e.g. Protobuff .proto files or the Java classes generated from them.
This is normally done by creating either a separate project or converting your micro-service projects into a multi-module projects where one of the modules is a thin API module with interface definition.
There is nothing wrong in sharing code between micro-services but you have to be careful. Share too much internal implementation details and you end up with a distributed monolith instead of micro-services.
You can create a separate project with common models, create a jar of this project and add dependency of this jar in other microservices.
But I have a practical experience, its a nightmare to maintain this common project, because for every change you have to create a new version and update the build scripts of all the microservices.
In my opinion we should not share models among the microservices.
In a Microservices architecture, each one is absolutely independent of the others and it must hide the details of the internal implementation.
If you share the model you are coupling microservices and lose one of the greatest advantages in which each team can develop its microservice without restrictions and the need of knowing how evolve others microservices. Remember that you can even use different languages in each one, this would be difficult if you start to couple microservices.
https://softwareengineering.stackexchange.com/questions/290922/shared-domain-model-between-different-microservices
If you are draconian about this decision you will run into unsatisfactory conditions one way or the other. It depends on your SDLC and team dynamics. At Ipswitch, we have many services that all collaborate and there are highly shared concepts like device and monitor. Having each service have its own model for those would be unsustainable. We did that in one case and the translation just created extra work and introduced inconsistency defects. But that whole system is built together and by one large dev team. So sharing makes the most sense there. But for an enterprise, where you have multiple teams and multiple SDLCs across microservices, it makes more sense to isolate the models to avoid coupling. Even then, however, a set of closely collaborating services that are managed by a given team can certainly share a model if the team accepts the risk/benefit of doing so. There is nothing wrong with that beyond academics and philosophy.
So in short, share minimally but also avoid unnecessary work for your team.
You could move your model classes to a different project/repository and add it as a dependency to your microservices that need to share it.
Not sure if your microservices use Swagger, but, you can use Swagger Codegen to generate your models.
For example, If you have UserService which accepts and/or returns User object. The consumer of UserService can use the Swagger Codegen plugin to auto-generate the User class at build time.
You can use Swagger Codengen maven or gradle plugin pretty easily.
JHipster is great. It, however, models all objects as domain entity objects. An enum class, for example, is treated as a domain class. If I want to practice the domain driven design, I need to convert some of entity classes, which are generated by JHipster, to value classes along with other types of changes such as replacing primitive types with domain object data types. Can I still run import-jdl after making such changes? In the other words, whether the changes are maintiable with a JDL?
BTW, there is a good talk on DDD by Edson Yanaga posted on youtube.
An interesting talk about DDD:
Implementing DDD with the Spring Ecosystem by Michael Plöd # Spring I/O 2018
There's a concept coming from the video, that I've found very important:
JPA entities are not domain entities.
JPA entities and repositories are what you use to persist data on the Db. While the Domain is what you use inside the application.
To answer, I think that you can build your domain classes separately, without caring too much about JPA entities. I suppose that's better to have a consolidated JPA layer before to start building the Domain side, if the two are somehow linked (and usually they are)
Please consider that I've just started to study this topic. Would be good to hear other opinions.
It's a pity that, in short, JHipster just does not support Value Objects, which makes it incomplete to design a DDD application by only caring about models.
See
issue1,issue2,another SO question
I am developing a spring restful application that uses hibernate. I am coming across scenarios where i had to place jackson json annotations on entity getters. Ex: One to Many mappings.
Is it a good idea to place jackson json annotations on hibernate entities? Or should i go with DTO pattern to pass data that is just needed by UI? I may end up creating a DTO for every entity.
Below is the application architecture. Common is at root level. DAO has dependency on Common and so on.
Common <- DAO <- Services <- Web
DAO has entities
Services or Web can have DTO's
Please let me know your thoughts or suggestions.
Disclaimer: I am speaking from opinion and experience here
Separate dto and entities are common practice. What you choose to do really depends on it's use. One of the drawbacks of adding DTO annotations on your data model entities is versioning. Versioning becomes hard when your data model is tied to your contract. If your webservice is only used by a consumer you own and its deploy schedule is the same then it's probably not worth separating dto/entities. If you don't need versioning and you mostly have CRUD web services then you may want to look into spring data rest.
If you arn't so lucky, and have multiple consumers, then you may want to think through a few version breaking changes and how you will handle it. This will help you see the value in separating the data and contract.
I would like to know how if there is any way to automatically generate a database administration site for a Spring + JPA project. It should take the annotated JPA entities and dynamically generate the site to keep track of any change in the domain Java classes.
I am looking for something similar to the Django admin site (I think you can also do the same with Ruby on Rails), that allows the user:
to see and update the data in the different tables without developing any extra code
to handle relations between tables, different kind of data (numbers, dates, etc)
In the Java world I am only aware of Spring Roo, but it does not fit my needs because I want to integrate it into an already existing third-party project.
Try Play! Framework's CRUD Module
My domain classes and persistance logic (Hibernate) are in one project called model. This jar is included within all of my apps.
Packaged com.company.model & com.company.persistance
Another Utils.jar - contains DateTime, String, Thread, etc general helper classes. This again is included within all of my apps.
Packaged com.company.utils
I have a CXF/Spring app that exposes services for manipulating my data. CRUD functionality, ALL other common functions. This is the 'way in' to my database for any app designed.
Packaged com.company.services and running on Glassfish app server
I have other apps that use the web services (Spring injected) to manipulate my data. Including a web app that will use YUI widgets and the XML/JSON from the web services for a nice smooth UI.
I understand its not really a question! I suppose Im looking for confirmation that this is how others are designing their software. If my architecture makes good, logical sense! Obviously there are security concerns - I will want some applications allowed to only access service x. I will address these later.
Sounds good.
It depends also of the type of application you're developing and the specific requirements for that ( it has to be deployed every week, it has to be deployed in several locations etc )
But so far sounds good enough.
Looks like you can formulate a question from here in the future for some specific scenario.
Since this is not a question, mine is not really an answer. CW
My only comment would be to put the persistence and Hibernate classes into a separate module; so that the model module can be purely beans/POJO/your domain classes.
Here's how I've organized a few multi-module projects before
project-data - contains domain classes and DAOs (interfaces only)
project-services - "Business logic" layer services, makes use of DAO interfaces.
Depends on project-data.
project-hibernate - Hibernate implementation of DAO interfaces.
Depends on project-data.
Conceivably if I were to use some other sort of data-access method I would just create a separate module for that. Client apps could then choose which modules to be dependent on.
Only suggestion I might have is that when you're creating service/models that you group them by subpackage name. ie
com.company.model.core
com.company.service.core
com.company.model.billing
com.company.service.billing
Also, be careful to ensure that no controller code (manipulating your UI) ends up in the services.