serializable vs. Session Beans (& designing a Value Object Facto

Discussions

EJB design: serializable vs. Session Beans (& designing a Value Object Facto

  1. I am in the process of building a J2EE system according to Sun's Patterns document and the many improvements Floyd M has suggested with his outstanding chapter on Value Objects. Here is my question.

    The top level of the "backend" to this J2EE system is the Facade level. The Facade objects (Session Beans) communicates with the Business Logic objects (Session Beans) or Value Object Factory.

    I am using Bi-modal data access and have designed a suite of plain-jane Data Access Objects (JDBC) that access the data I need. The Value Object Factory can also communicate with the Entity Beans and I am planning on using the "local" interface to those beans (to cut out the JNDI and marshalling).

    WHEW! :-) One more fact (I promise). I have no intention of the Value Object Factory, DAOs, and Entity Beans being on different JVMs (i.e, different boxes). IMHO, there is no point to that.

    I initially made the Value Object Factory implement java.io.serializable. I now see that was a bad decision if I want to put Business Logic and Facades on a different box/JVM. I should just make the Value Object Factory a Session Bean so that JNDI can "track them down" no matter where they exist.

    If I make the the Value Object Factory a Session Bean, does that automatically make the Value Objects themselves serializable? Do I also need to make the Value Objects themselves implement java.io.serializable?

    An even more basic question to all of this is where would someone *want* to use java.io.serializable?

    HELP!
  2. yes and no....
    in you'r case...since it's stateless... it doesnot matter...your value objects become the implementation and you have the remote interface through which components make remote-calls to it, and since only simple business logic, the answer is yes.

    But if anybody's interested SessionBean extends EnterpriseBean, which Implements Serializable. Thus if you were to include some non-serializable attributes in your implementation of the SessionBean (i.e. a design not complying with the specs) like Threads or IOStreams, the container would get an Exception when trying to serialize the bean....
  3. Aditya, could I please ask you to elaborate on your reponse? I'm having trouble following it.

  4. ooops.... I read you'r post again... i missed some of it the first time... and i apologise... the value objects themselves will not be serialized... you need to explicitly declare them as 'implements Serialized'
  5. I am using J2ee 1.3 and trying to implement this design. but get a similar error to what is being talk about here about serialising. I seem to get a classCastExcep. when I return the bean.

    If you could help I would greatly appreciate it.
     
    This short article is a really good alternative to Value Objects.
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1208-clones.html
     
     
    Does anyone have any idea why I cannot return my Bean. As these articles instruct I call the getAstralClone and "return this;" (within my bean) but receive a casting error. Can anyone help?(I'm using CMP2.0 J2ee 1.3)
     
    Thanks in advance
    Glenn Dickson
  6. Dave,
    If your value objects need to pass between remote objects/JVMs, you'll need to make each value object serializable. Any Java object that needs to be passed between remote objects needs to be serialized and hence must implement the java.io.Serializable interface.

    Does that answer your question?
    --Suraj