1 Reply Latest reply on Mar 1, 2006 11:32 AM by acoliver

    Problem with accessing the size of a message.

    sappenin

      I'm playing around with JBMS some more, and it appears that JBMS is having some trouble with the following JavaMail POP3 calls.

      Specifically, the ejb3 org.jboss.mail.mailbox.Folder.messages code (I'm running JBMS 1.0M4) has an issue with accessing a message via a folder, and also with accessing the "size" of a message(?)

      Here's what I was able to figure out so far.

      First, If I run the following code to try and fetch some messages via POP3, then I get a LazyInitializationException upong trying the fetch. (Note: I'm using standard JavaMail classes like Message, etc. The MBox variable is a class-level POP3Folder that is opened in a separate function. Via debugging, I have been able to verify that it is indeed connected to JBMS.)

      Message[] msgs = getMbox().getMessages(begin, end); //'getMBox()' verifies that the POP3Folder 'mbox' is connected, and returns that POP3Folder.
      FetchProfile fp = new FetchProfile();
      fp.add(Item.ENVELOPE);
      fp.add(Item.FLAGS);
      fp.add(Item.CONTENT_INFO);
      fp.add("Size");
      fp.add("Date");
      mbox.fetch(msgs, fp); //This call throws a LazyInitializationException
      
      ............
      
      {getMBox() above connects as follows...}
      
      Properties props = System.getProperties();
      Session session = Session.getDefaultInstance(props, null);
      store = session.getStore("pop3");
      store.connect(serverName, port, username, password);
      mbox = store.getDefaultFolder();
      mbox = mbox.getFolder("INBOX");
      mbox.open(Folder.READ_WRITE);
      
      


      The above code results in a LazyInitializationException as follows:

      09:46:43,000 ERROR [LazyInitializationException] failed to lazily initialize a collection of role: org.jboss.mail.mailbox.Folder.messages, no session or session was closed
      org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: org.jboss.mail.mailbox.Folder.messages, no session or session was closed
       at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
       at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
       at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
       at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
       at org.hibernate.collection.PersistentBag.get(PersistentBag.java:398)
       at org.jboss.mail.mailbox.Folder.getMessageAt(Folder.java:138)
       at org.jboss.mail.pop3.handlers.CmdLIST.handleRequest(CmdLIST.java:85)
       at org.jboss.mail.pop3.POP3ProtocolInstance.handleRequest(POP3ProtocolInstance.java:202)
       at org.jboss.mail.ConnectionHandler.runSocket(ConnectionHandler.java:188)
       at org.jboss.mail.ConnectionHandler.run(ConnectionHandler.java:82)
       at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:743)


      However, if I fetch a message using the following code, then no exception is thrown (notice only the last line changed):

      Message[] msgs = getMbox().getMessages(begin, end); //'getMBox()' verifies that the POP3Folder 'mbox' is connected, and returns that POP3Folder.
      FetchProfile fp = new FetchProfile();
      fp.add(Item.ENVELOPE);
      fp.add(Item.FLAGS);
      fp.add(Item.CONTENT_INFO);
      fp.add("Size");
      fp.add("Date");
      ((POP3Store)(mbox.getStore())).getDefaultFolder().fetch(msgs, fp);
      //mbox.fetch(msgs, fp);
      


      First, is this a bug? The only difference between the two sets of code is that one calls a fetch on the default folder of the store, and the other calls a fetch on the "INBOX". It could be the case that JBMS is designed to only access messages this way. However, if this is not a bug, then not all of the JavaMail classes work properly, which might be an issue(?)

      This wouldn't be such a big deal, except that if I successfully retrieve a JavaMail "Message" object using the latter method (that actually lets me retrieve the headers), and then send that Message object to the test function below, I get the same LazyInitializationException, but only when I call p.getSize(). All of the other functions work appropriately.

      public void testFunction(Part p)
      {
      p.getContentType(); //works.
      p.getFileName(); //works.
      p.getDisposition(); //works.
      p.getContent(); //works.
      p.getSize(); //This call produces a LazyInitializationException as seen above.
      
      }
      


      Any thoughts here? From what I can tell, the Hibernate Fetch Eagerness on the org.jboss.mail.mailbox.Folder.messages annotation is set to Lazy. However, only retrieving the size appears to set off the exception. I can get other things like Content, headers, etc, without any trouble.

      Thanks!

      David


        • 1. Re: Problem with accessing the size of a message.
          acoliver

          You need to do this inside of a transaction. You can do this either by using CMT with Stateless Session Beans... or you can do this by calling UserTransaction. All of the mailbox calls should be behind a transaction.

          We DO need to divide up a public vs private API really soon. having some proposals on that would be helpful. I'd prefer to abstract hibernate and the page vs unpaged store out of it though...