Storing a ByteBuffer into a Cassandra database
I cannot see anything wrong with the way you are using it. The example is a little contrived (given that you are not actually using cassandra), and the only things I can see that look odd are a direct result of that.

Bottom line is that it appears to be a fine piece of code (which is perhaps why there have been no reviews so far).

As for some nit-picky things:

I don't like that you are hard-coding the size of the buffer (on the write-side): int size = 2 + 8 + 4 + attributeValue.length is 'ugly'.

I tend to do th 'overkill' approach and use a buffer that is always too big. I find memory is cheap for the occasional buffer (even up to a couple of megs of memory...). I then make the buffer a thread-local so that I am not always creating new buffers. In your example it is trivial because it is all in the main method.... but for a 'real' program you may want to reconsider. If you know your data will always be less than, say 4K, I would instead do the following on the write side:

// a 'smaprt' implementation will make the buffer a ThreadLocal,
// and will also make it grow, if needed.
ByteBuffer bbuf = ByteBuffer.allocate(4096);
bbuf.order(ByteOrder.BIG_ENDIAN);


Then, your code should reset the buffer before using it:

bbuf.clear(); // position to 0, limit to capacity
bbuf.putShort(employeeId);
bbuf.putLong(lastModifiedDate);
bbuf.putInt(attributeValue.length);
bbuf.put(attributeValue);


Now, instead of doing a rewind(), do a flip()

bbuf.flip(); // limit to position, position to 0
byte[] bytesToStore = new byte[bbuf.limit()];
bbuf.get(bytesToStore);


The advantage of the above is that you do not need to manually track the size of your data, and you do not need to keep allocating new ByteBuffers each time,