3 Replies Latest reply on Nov 14, 2002 6:06 AM by Mark Crowley

    Read JAVA_OBJECT from store

    Mark Crowley Newbie

      Hi.

      I have a JAVA_OBJECT stored in a image field on a SQL7 database.

      The object was placed there by a CMP EJB.

      I need to (for reasons too boring to explain) read this object directly through JDBC.

      I have tried using the getBlob, getBinaryStream,, and getBytes methods of ResultSet along with ObjectInputStream and casting the result to my object but I get various Class Cast exceptions.

      I'm sure i'm missing something simple here.

      Does JBoss (2.4.4) serialize objects its own way?

      Thanks in advance for your help.

        • 1. Re: Read JAVA_OBJECT from store
          Stephen Coy Novice

          With the caveat that I have not looked at the 2.4 source, JBoss versions prior to 3.0.4 used their own marshalling/demarshalling scheme for jdbc JAVA_OBJECT types. I would not be surprised if the 2.x series did the same.

          In order the recover the object, you'll need to inspect the 2.4 source and find out how it was stored.

          Note that there are clear semantics in the JDBC docs for using using JAVA_OBJECT, which JBoss previously ignored. You probably should be using one of the BINARY jdbc type variants unless you know what what you're doing.

          Steve

          • 2. Re: Read JAVA_OBJECT from store
            Mark Crowley Newbie

            Found it. For anyone interested...

            Any object stored is wrapped as a java.rmi.MarshalledObject

            So you need to do the following:

            ResultSet rs = .....

            ByteArrayInputStream bis = new ByteArrayInputStream(rs.getBytes(...));
            ObjectInputStream ois = new ObjectInputStream(bis);
            Object o = ((MarshalledObject) ois.readObject()).get();
            ois.close();

            You can then cast 'o' to your specific object type.

            • 3. Re: Read JAVA_OBJECT from store
              Mark Crowley Newbie

              Found it. For anyone interested...

              Any object stored is wrapped as a java.rmi.MarshalledObject

              So you need to do the following:

              ResultSet rs = .....

              ByteArrayInputStream bis = new ByteArrayInputStream(rs.getBytes(...));
              ObjectInputStream ois = new ObjectInputStream(bis);
              Object o = ((MarshalledObject) ois.readObject()).get();
              ois.close();

              You can then cast 'o' to your specific object type.