How do I disable lazy loading in Hibernate? I am using persistence annotations, not an hbm xml file.
I am fetching a single object by ID and want all properties loaded. The session is closed before I use the object.
Thanks!
You need to annotate the properties that you want non-lazy loaded with FetchType.EAGER
@ManyToOne(fetch = FetchType.EAGER)
You see, it isn't the object that you are loading that is lazy loaded. Rather, that object's associations are lazy, and you need to tell them not to be if that is your desired behavior.
If those objects also have associations that you want loaded eagerly, you need to annotate them as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With