Using enumerated types with EJBs


EJB programming & troubleshooting: Using enumerated types with EJBs

  1. Using enumerated types with EJBs (2 messages)

    I have an class that is an enumerated type:

    public class MyType implements Serializable {
      public final static MyType TYPE1 = new MyType();
      public final static MyType TYPE2 = new MyType();

    When I use this type in a business object that is returned from a session bean method, the type is broken. I understand why, because I'm using references which are equal only in the same process. So my question is how can I implement an enumerated type that will work with EJB (for remote calls)? Is there a pattern for this?

  2. Well u can pass constant string as contstructor parameters for MyType object. And then override the equals method which compares the equality of the string.
  3. Using enumerated types with EJBs[ Go to top ]

    You need to use the canonical Java enumerated type pattern, which works with serialisation.

    See Bloch's book 'Effective Java'