I am using JPA(with Hibernate 4.3.3 as persistence provider ) along Spring (3.2.2) , all my fields are loading fine but when I am trying to access my Collection it\'s throwing t
Like @Zeus said, this has been answered many, MANY, times before. You are having this problem in your test class because your transaction begins and ends at your service call:
Category parentCategory=serviceCategory.findCategoryById(2l);
Recall from Hibernate documentation that lazy loading only works within a Hibernate Session (in this case, the hibernate session begins and ends with your service call). You can't reconnect to the hibernate session (simply) to initialize the collection.
I'm not exactly sure what you mean when you want to solve it "in spring." Since this isn't a Spring issue. Essentially the two ways to resolve this are to load the collection within the hibernate session you load the parent in or execute a separate fetch outside of the original hibernate session.