-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: LazyInitializationException, not typical OSIV issues
PostPosted: Thu May 28, 2009 2:50 am 
Newbie

Joined: Sat Jan 06, 2007 3:46 pm
Posts: 15
Hi. I have a fairly simply bit of code that fetches a list of objects, and then for each one, accesses a collection on that object. The first query is fine, but accessing the collection fails with failed to lazily initialize a collection of role: foo, no session or session was closed.

Normally I'd think I forgot my OpenSessionInView filter and fix it. But that's not used in this case. The code is:

Code:
   public
   List<Mission>
   getMissionList(String inDeviceID, String inUserAgent, Date inLastFetch)
   {
      try
      {
         ServletContext ctx = getServletContext();
         WebApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(ctx);
         IService s = (IService) springContext.getBean("service");
         
         Date lastRequestDate = inLastFetch;
         if (inLastFetch == null)
         {
            DataRequest lastRequest = s.getMostRecentRequest(inDeviceID);
            lastRequestDate = lastRequest.getDate();
            sLogger.debug("No lastFetchDate from client, got from last request record");
         }
         
         sLogger.debug("Last fetch date: " + lastRequestDate);
         
         //   Fetch the Missions…
         
         int         numMissions = 0;
         int         numEvents = 0;
         int         numNewsItems = 0;
         
         sLogger.info("Requesting missions since " + lastRequestDate + " for device " + inDeviceID);
         List<Mission> missions = s.getMissionList(lastRequestDate);
         sLogger.debug("Got " + missions.size() + " missions.");
         
         numMissions += missions.size();
         
         for (Mission m : missions)
         {
            numEvents += m.getEvents().size(); // EXCEPTION HERE
         }

         sLogger.info("Sent device [" + inDeviceID + "] "
                     + numMissions + " missions, "
                     + numEvents + " events, "
                     + numNewsItems + " news items.");
         return missions;


The exception occurs in getEvents().size().

Events are mapped with:

Code:
   @OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, mappedBy = "mMission")
   private   Set<MissionEvent>   mEvents   =   new HashSet<MissionEvent>();


Now, this used to work, but it was a while back, and I'm not sure if I changed anything. Source control shows nothing obvious. The first request works, the second does not.

For a while I thought it was because I was releasing the session in the getMissionList() method, but I tried commenting out that release, and it still happens.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.