1 Reply Latest reply on Jan 8, 2002 10:59 PM by adrian.brock

    Ejb database connection serialization.

    gordonlch

      Hi all,

      I have a question on ejb, that is mostly i write ejb, i also define a private variable (java.sql.Connection) for connection ref., sure, when the ejb life up, i will lookup 'Datasoure' and get the connection. The question is , when jboss need my ejb take serialization, it report the connection ref. could not ser., it's true, java.sql.Connection could not ser., i want the answer is , what's your program pattern use? don't use a private vairable for connection ref.?

      Gordon

        • 1. Re: Ejb database connection serialization.

          You need to take over serialization of your class.

          Instead of
          ObjectOutputStream.writeObject(connection);

          do

          ObjectOutputStream.writeObject(informationToGetConnection);

          and instead of
          ObjectInputStream.readObject(connection);
          do

          ObjectInputStream.readObject(informationToGetConnection);
          connection = getConnection(informationToGetConnection);

          Be careful with where your object is transferred to.

          If it goes over a network and you put a password
          in the stream somebody can sniff it,
          it probably won't be encrypted.
          Regards,
          Adrian