Hibernate ManyToOne FetchType.LAZY is not working?

前端 未结 3 517
情歌与酒
情歌与酒 2021-01-15 12:13

I am using spring 4.1.4.RELEASE + hibernate 4.3.6.Final, here is my entity code:

public class BaseEntity implements Serializable {
}


public class MarketInf         


        
相关标签:
3条回答
  • 2021-01-15 12:50

    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.

    0 讨论(0)
  • 2021-01-15 12:58

    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.

    0 讨论(0)
  • 2021-01-15 13:08

    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;
    }
    
    0 讨论(0)
提交回复
热议问题