how to handle lazy loading using spring data jpa and spring boot?

how to handle lazy loading using spring data jpa and spring boot?    when i tried to retrive the  data on the proxy object its throwing LazyInitialization checked exception. How to avoid that kind exception?

Add Comment
1 Answer(s)

The best way is  use entity graphs:

 

@Entity
@Table(name = PROFILE)
        @NamedEntityGraph({
                name = Profile."FETCHRECORDS",
                attributeNodes = {
                        @NamedAttributeNode("person")
                        @NamedAttributeNode(value = "address", subgraph = Profile.GETPHONE)},
                subgraphs = {

                        @NamedSubgraph(name = Profile.GETPHONE,
                                attributeNodes = {
                                        @NamedAttributeNode("phone")
                                }),

                        
                })

Class Profile{

public static final String FETCHRECORDS = "fetchRecords";
public static final String GETPHONE = "getPhone";



private String name;


}


Answered on February 6, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.