solution in talend to read/write oid data of postgres havin Java class

solution in talend to read/write oid data of postgres havin Java class

The major task of our assignment includes

1. Retrieving an oid type data in postgres which stores java object (which is created using EJB) as bytes and converting the bytes into specific object in java .
2. Then retrieving the data stored in that java object and setting the data in a new java object.
3. Then converting that object to bytes and storing in an oid field of postgres table.


By creating a routine (This routine is called in tJavaRow component of talend) in talend which is using java classes ByteArrayInputStream and ObjectInputStream we tried to convert the bytes to object. We got object but with null value. We tried various other ways but still same problem persists.

Please suggest me whether there is any other way in talend to read and write oid type data containing Java classes as mentioned above.
Thanks in advance
Bhaskar
One Star

Re: solution in talend to read/write oid data of postgres havin Java class

Hello,
It seems to me you'r confusing something. An oid is just an object identifier to make reference, it contains no actual value and have only a logical sens. Now actual objects in java can be serialized several ways in java, the default way (when the class implements "serializable") is to a byte array. In databases it should correpond to a BLOB type (at least in Oracle database, I don't know for postgres).
Using talend and an Oracle database, I've read in the past row with BLOB types. I forced the type to byte[] and I retrieved the correct value.
In Talend, I've never done the next step, to deserialize from byte[] to Object.
ObjectInputStream is the right way, but U'll need to load the actual class via a tLibraryLoad to have something different from just 'Object'.

Re: solution in talend to read/write oid data of postgres havin Java class

Thanks for the quick response.
I am aware of the oid data type and know that it is making a reference to the actual storage.
My problem is to deserialize from byte[] to Object. Upto this step I have done it correctly.
I am not able to typecast the EJB object to simple Java class
Thanks
Bhaskar
One Star

Re: solution in talend to read/write oid data of postgres havin Java class

Before hand, the Object shouldn't be null. Maybe check that u'r using the same version of java for serializing and deserializing.
ObjectInputStream  in = new ObjectInputStream(new ByteArrayInputStream(bytes));
object obj = in.readObject();

Then u should try to load the .jar containing the class of the EJB, then u'll be able to cast this Object to the actual class.
ActualClass classInstance = (ActualClass)obj;

Re: solution in talend to read/write oid data of postgres havin Java class

I am using the java 1.3 version for serializing and java 1.5 version for deserializing. I presume that I am typecasting object from lower version to higher version that should not have any compatibility issues.
Plus I am using exactly same syntax as given by you and the result is not desired as stated earlier.
The only problem I see is that objects are created using the EJB framework and I am typecasting these objects in a simple java type without EJB framework???
Thanks
Bhaskar
One Star

Re: solution in talend to read/write oid data of postgres havin Java class

This might have to do with the JVM version still. It seems possible to specifiy with version of the serialization protocol to use. See : http://macchiato.com/columns/Durable4.html
I'm sorry don't have time to reproduce your pb to work on it more than that.
Good luck!