tx.begin();
for (int i = 1; i < NUMBER_TO_INSERT; ++i) {
// must be done with an active transaction
ClobTypes e = em.find(ClobTypes.class, i);
// see if it is the right one
int actualId = e.getId();
if (actualId != i) {
error("Expected ClobTypes.id " + i + " but got " + actualId);
}
String string = e.getLarge10000();
// make sure all fields were fetched properly
checkString("before update", string, i, false);
int position = getClobSizeFor(i)/2;
// only update if the length is correct
if (string.length() == (position * 2)) {
StringBuilder sb = new StringBuilder(string);
// modify the byte in the middle of the blob
sb.replace(position, position + 1, "!");
string = sb.toString();
checkString("after update", string, i, true);
}
e.setLarge10000(string);
}
tx.commit();
tx.begin();
for (int i = 1; i < NUMBER_TO_INSERT; ++i) {
// must be done with an active transaction
ClobTypes e = em.find(ClobTypes.class, i);
// see if it is the right one
int actualId = e.getId();
if (actualId != i) {
error("Expected ClobTypes.id " + i + " but got " + actualId);
}
String string = e.getLarge10000();
// check to see that the blob field has the right data
checkString("after commit", string, i, true);
}
tx.commit();