[英]JHipster : Generate MongoDB entities with JHipster Domain Language (JDL)
I'm trying JHipster with a MongoDB database. 我正在尝试将MongoDB数据库用于JHipster。 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…
为此,我想使用JDL格式来生成实体,存储库,服务,dtos ...
This is my actual JDL file: And it works : 这是我实际的JDL文件:它可以正常工作:
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
. 现在,我想补充一下
Author
可以写一Book
的概念。
I can add an entity Author
: 我可以添加一个实体
Author
:
entity Author {
firstane String required
lastname LocalDate required
}
My specific question is: How can I associate an Author
and a Book
? 我的具体问题是:如何关联
Author
和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. 但这不起作用,因为NoSQL数据库不支持关系。 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.
使用NoSQL数据库,这成为一个更重要的问题。 Let's assume you want to return an author and all their books as a single document.
假设您想将一个作者及其所有书籍作为一个文档返回。
Here are some options: 以下是一些选项:
Author
. 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. $lookup
功能来获取给定作者的书。 The DBRef
feature in spring-data-mongo might help in this case. DBRef
功能可能会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.