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 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.