Hibernate ManyToOne FetchType.LAZY is not working?

最后都变了- 提交于 2019-12-01 13:21:18

Move the @OneToMany annotation from the declaration to the getter method, like this:

private List<MarketChannelGroup> channelGroups;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "market")
public List<MarketChannelGroup> getChannelGroups() {
    return channelGroups;
}

How is your configuration archive? Look if you are using the filter OpenEntityManagerInViewFilter. If you are using it, always that you call the method Lazy getChannelGroups() the hibernate will get fetch inside each element.

You have to take oneToMany annotation to getter if @id is on the getter. Lazy works but if you or some framework get the lazy property in that transction the get method fire the select.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!