I'm trying JHipster with a MongoDB database. For my example I would like to store Books. To do that I would like to use the JDL format to be able to generate entities, repositories, services, dtos…
This is my actual JDL file: And it works :
entity Book {
name String required
date LocalDate required
}
dto all with mapstruct
paginate all with pager
service all with serviceImpl
Now, I would like to add the notion that a Book
can be written by an Author
.
I can add an entity Author
:
entity Author {
firstane String required
lastname LocalDate required
}
My specific question is: How can I associate an Author
and a Book
?
The documentation has this example :
relationship OneToMany {
Author{book} to Book{writer(name) required}
}
But that's not working because NoSQL databases don't support relationships. So, how can I achieve that ?
Thanks.
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 . jhipster folder.
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.
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.
You haven't said exactly what you want to do with your entities. With NoSQL databases this becomes a more important question. Let's assume you want to return an author and all their books as a single document.
Here are some options:
Author
. Unfortunately JHipster does not seem to allow you to define list types as entity fields so you will have to add this to the Java code yourself.$lookup
feature in mongodb 3.2 to fetch Books for a given Author. The DBRef
feature in spring-data-mongo might help in this case.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With