如何在弹簧数据JPA中以一对多映射中的一对多映射中获取所有连续记录?
我创建了两本简单的模态书籍和作者,作者有很多书。该映射正在起作用,当我将作者与Postman的书籍毫无意义一起保存时,它都会根据两张表保存,但是当我遇到查询以获取所有作者或所有书籍时,它不会响应。 它与DTO有关吗?我如何获取数据,我不想使用加入查询等。 请指南。
I have created two simple modal entities Book and Author and an author has many books. The mapping is working and when I save author along with book abjects from postman it gets saved according in both tables but when I hit query for fetching all authors or all books it does not respond.
Is it something related to DTOs? How can I fetch the data, I don't want to use Join Query etc.
Please guide.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@Onetomany
具有参数fetchType(Enumeration)fetch
。它是fetchtype.lazy
默认情况下,您应该将其更改为fetchType.eager
。如果参数获取为fetchType.lazy
Hibernate在调用之前不会获得书籍实体。如果获取为fetchType.eager
如果您不调用它,请获得书本实体。@OneToMany
has parameterFetchType(Enumeration) fetch
. It beFetchType.LAZY
by default, you should change it toFetchType.EAGER
. If parameter fetch isFetchType.LAZY
Hibernate doesn't get Book entities until you call it. If fetch isFetchType.EAGER
than Hibernate gets Book entities if you didn't call it.