title: how to get back the java UUID stored in DB as binary
body: <p>We have a Java UUID field that is stored in database (MySQL) as binary bytes after the following conversion</p>
  
  <pre><code>private byte[] getUUIDtoBytes(UUID devId) {
      byte[] uuidBytes = new byte[16];
      ByteBuffer.wrap(uuidBytes)
              .order(ByteOrder.BIG_ENDIAN)
              .putLong(devId.getMostSignificantBits())
              .putLong(devId.getLeastSignificantBits());
      return uuidBytes;
  </code></pre>
  
  <p>And after retrieving it from DB using resultSet.getBytes, the byte array is converted back to UUID in the following way</p>
  
  <pre><code>private UUID toUUID(byte[] bytes) {
      ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
      Long high = byteBuffer.getLong();
      Long low = byteBuffer.getLong();
  
      return new UUID(high, low);
  }
  </code></pre>
  
  <p>This works fine until now I have to find the UUID field of a row in production. The application that displays the record probably uses the getText or getString to show the byte arrays and just by getting the byte array of the result string (with UTF-8) and applying my toUUID method, I cannot get back the UUID value of the record :(</p>
  
  <p>Unfortunately, all the retrieval endpoints of our service require this UUID field. Can I have some hint on how I may possibly use the string format of that byte array, and convert it back to the original UUID?</p>