tx.begin();
for (int i = 1; i < NUMBER_TO_INSERT; ++i) {
// must be done with an active transaction
BlobTypes e = session.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);
// mark the field as modified so it will be flushed
session.markModified(e, "blobbytes");
// update the modified instance
session.updatePersistent(e);
}
}
tx.commit();
tx.begin();
for (int i = 1; i < NUMBER_TO_INSERT; ++i) {
// must be done with an active transaction
BlobTypes e = session.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", e.getBlobbytes(), i, true);
}
tx.commit();
}