SecondaryKeyMetadata secKeyMeta =
entityMeta.getSecondaryKeys().get(keyName);
assertNotNull(secKeyMeta);
/* Create key creator/nullifier. */
ForeignMultiKeyNullifier keyNullifier = new PersistKeyCreator
(catalog, entityMeta, keyCls.getName(), secKeyMeta);
/* Convert entity to bytes. */
PersistEntityBinding entityBinding =
new PersistEntityBinding(catalog, entityCls.getName(), false);
entityBinding.objectToData(entity, dataEntry);
entityBinding.objectToKey(entity, keyEntry);
/* Get secondary key binding. */
PersistKeyBinding keyBinding =
new PersistKeyBinding(catalog, keyCls.getName(), false);
DatabaseEntry secKeyEntry = new DatabaseEntry();
/* Nullify one key value at a time until all of them are gone. */
while (true) {
Object fieldObj = getField(entity, keyName);
fieldObj = nullifyFirstElement(fieldObj, keyBinding, secKeyEntry);
if (fieldObj == null) {
break;
}
setField(entity, keyName, fieldObj);
/* Nullify secondary key bytes within entity bytes. */
boolean isKeyPresent = keyNullifier.nullifyForeignKey
(null, keyEntry, dataEntry, secKeyEntry);
assertEquals(keyValue != null, isKeyPresent);
/* Convert modified entity bytes back to an entity. */
Object entity2 = entityBinding.entryToObject(keyEntry, dataEntry);