If you have any objects in that resultset which are lazily loaded,
then closing the entity manager before you've looped through the
resultset will produce an exception and the route to the data store to
retrieve the data has been closed.

You have two options:

1) Aggressively fetch the data which you're looping through, so that
all data is retrieved from the data store before you iterate over it.
2) Close the entity manager after you've looped through the required
data.

On Nov 16, 3:51 am, YONG <yongkia...@gmail.com> wrote:
> Hi, I want to know what is the different of this code when compiling
> and execute in GAE.
>
> <%
>         EntityManager em = EMF.getInstance().createEntityManager();
>         List<User> users = (List<User>) em.createQuery(
>                         "SELECT FROM " + 
> User.class.getName()).getResultList();
>         request.setAttribute("rs", users);
>         em.close();
> %>
>
> <display:table requestURI="displaytag.jsp" name="rs" export="true"
>         sort="list" pagesize="10" class="display">
>         <display:column property="id" title="User ID" sortable="true"
>                 headerClass="sortable" />
>         <display:column property="name" title="User Name" sortable="true"
>                 headerClass="sortable" />
>         <display:column property="gender" title="Gender" />
>         <display:column property="aboutYou" title="About You" />
>         <display:column property="country" title="Country" />
>         <display:column property="mailingList" title="JOIN?" />
> </display:table>
>
> The above code is giving error code HTTP 500. However, when I change
> to
>
> <%
>         EntityManager em = EMF.getInstance().createEntityManager();
>         List<User> users = (List<User>) em.createQuery(
>                         "SELECT FROM " + 
> User.class.getName()).getResultList();
>         request.setAttribute("rs", users);
>         // em.close(); // just comment this line and move it down
> %>
>
> <display:table requestURI="displaytag.jsp" name="rs" export="true"
>         sort="list" pagesize="10" class="display">
>         <display:column property="id" title="User ID" sortable="true"
>                 headerClass="sortable" />
>         <display:column property="name" title="User Name" sortable="true"
>                 headerClass="sortable" />
>         <display:column property="gender" title="Gender" />
>         <display:column property="aboutYou" title="About You" />
>         <display:column property="country" title="Country" />
>         <display:column property="mailingList" title="JOIN?" />
> </display:table>
>
> <%
>         em.close();
> %>
>
> Then the JSP is running and show the result in displaytag table.
>
> Anyone can explain why?

--

You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=.


Reply via email to