On Wed, May 16, 2001 at 12:32:59PM +0200, Martin Renner wrote:
> Hi.
> 
> First of all: Sorry, but I was quite busy those last days. So it took some days to 
> answer your mail.
> 
> Toby wrote:
> 
> >On Thu, May 10, 2001 at 03:58:23PM +0200, Martin Renner wrote:
> >>As far as I know, every instance variable of an EJB has to be serializable or 
>marked 
> >>as transient (because the EJB by itself is implementing java.io.Serializable).
> >>
> > 
> > The relevent section of the spec (version 2.0pd2) is 6.4.1.
> 
> 
> Okay, I just was reading this section (btw: it's 6.4.1 in 2.0pd and 7.4.1 in 
>2.0pfd2).

Doh!  I was reading public draft 2 instead of public *final* draft 2.

> 
> >>IMHO EJBContextImpl should be serializable so that I can hold a reference to it, 
>or 
> >>am I wrong?
> 
> 
> According to the spec, I was wrong :-)
> 
> And now I know, why I got those NotSerializable exceptions:
> 
> A method of my EJB returns a SortedSet. To create this SortedSet, I am using a 
> TreeSet with a Comparator. This Comparator was an inner class of my EJB:
> 
> public class MyEJB ...
>      public SortedSet getSomething() {
>          return new TreeSet(new MyComparator());
>      }
> 
>      class MyComparator implements Comparator, Serializable {
>          public int compare(Object o1, Object o2) {
>          }
>      }
> }
> 
> When this SortedSet was returned to the client, the JVM returned the SortedSet AND 
> its Comparator, because the comparator is an attribute of the TreeSet. So the JVM 
> wanted to serialize the inner class (MyComparator) AND the EJB. Then, of course, I 
> got an exception, that EntityContextImpl is not serializable.
> 
> When I removed MyComparator from the EJB and turned it into a standalone class, 
> everything worked fine. It also works fine, if I don't use a Comparator and all the 
> elements of the SortedSet implement the Comparable interface.

You could make your inner class static, then it won't need to serialise its
containing instance.

Toby.

_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to