ObjectAccessor accessor = new ObjectAccessor();
accessor.toBytes(10);
byteCollection.put("key1", accessor.toBytes(10));
byteCollection.put("key2", accessor.toBytes(11));
EntityWithCollection entity = new EntityWithCollection();
entity.setId("entityId1");
entity.setDataMap(byteCollection);
em.persist(entity); // persist entity.
em.clear();
EntityWithCollection result = em.find(EntityWithCollection.class, "entityId1");
Assert.assertNotNull(result);
byte[] bytes = result.getDataMap().get("key1");
Object value = PropertyAccessorHelper.getObject(Object.class, bytes);
Assert.assertEquals(10, value);
// set list
List<byte[]> listAsBytes= new ArrayList<byte[]>();
UUID randomId = UUID.randomUUID();
listAsBytes.add("Vivek".getBytes());
listAsBytes.add(new UUIDAccessor().toBytes(randomId));
result.setListAsBytes(listAsBytes);
em.merge(result); // merge with list as bytes.
em.clear(); // clear from cache.
result = em.find(EntityWithCollection.class, "entityId1");
Assert.assertNotNull(result);
assertOnList(result, randomId);
Set<byte[]> setAsBytes = new HashSet<byte[]>();
setAsBytes.add("Vivek".getBytes());
setAsBytes.add(new UUIDAccessor().toBytes(randomId));
result.setSetAsBytes(setAsBytes);
em.merge(result); // merge with list as bytes.
em.clear();
result = em.find(EntityWithCollection.class, "entityId1");
Assert.assertNotNull(result);
assertOnList(result, randomId);
Set<byte[]> resultAsBytes = result.getSetAsBytes();
// on set type.
for(byte[] recInBytes : resultAsBytes)
{
assertBytes(randomId, recInBytes);