I have a school entity and it has a many to many relationship with grade-levels. I can successfully load my school object and send it to my view (which is a .ftl page, not jspx) the problem is; when I request the url as a JSON (to only receive the serialized data)(which I use to populate fields after doing a jquery get) I get a --failed to lazily initialize a collection of role:-- I have found that when I request a page as JSON and the object does not have a many to many relationship it will give me the serialized string just fine, however when the object has a many to many relationship I get that error. Has anyone come across this error, or know what I need to do?
I found this solution but i dont know if it is the best... any opinions... i added this code to my web.xml file
<filter>
<filter-name>OpenEntityManagerInViewFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenEntityManagerInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
this allowed the object to come back. hope it helps anyone that was trying to do the same thing. does anyone have a better solution or is this correct?
thanks everyone