tx.begin();
for (int i = 1; i < NUMBER_TO_INSERT; ++i) {
// must be done with an active transaction
BlobTypes e = em.find(BlobTypes.class, i);
// see if it is the right one
int actualId = e.getId();
if (actualId != i) {
error("Expected BlobTypes.id " + i + " but got " + actualId);
}
byte[] bytes = e.getBlobbytes();
// make sure all fields were fetched properly
checkBlobbytes("before update", bytes, i, false);
int position = getBlobSizeFor(i)/2;
// only update if the length is correct
if (bytes.length == (position * 2)) {
// modify the byte in the middle of the blob
bytes[position] = (byte)(position % 128);
checkBlobbytes("after update", bytes, i, true);
}
}
tx.commit();
tx.begin();
for (int i = 1; i < NUMBER_TO_INSERT; ++i) {
// must be done with an active transaction
BlobTypes e = em.find(BlobTypes.class, i);
// see if it is the right one
int actualId = e.getId();
if (actualId != i) {
error("Expected BlobTypes.id " + i + " but got " + actualId);
}
byte[] bytes = e.getBlobbytes();
// check to see that the blob field has the right data
checkBlobbytes("after commit", bytes, i, true);
}
tx.commit();