I use in my application GENERATE_UNIQUE() to create IDs.
When I create a POJO object from a table row I use rs.getBytes("ID")
and when I write it back to table I use ps.setBytes(object.getID)
. According to comments to this question: How to use value generated by GENERATE_UNIQUE() function as foreign key?
But during the POJO lifecycle I need a String
representation of an ID.
I can maintain second property to store ID as a String
but looking for a solution where I can convert from byte[]
to String
and back without loosing data.
I tried the following code in various variations but byte[]
array which I get back isn't the same as an initial byte[]
array.
byte[] result = rs.getBytes("ID");
String test = result.toString();
byte[] test1 = test.getBytes();