// Load the InstalledPackage to get its package version for the relationship
InstalledPackage ip = entityManager.find(InstalledPackage.class, installedPackageId);
PackageVersion packageVersion = ip.getPackageVersion();
// Create the history entity
InstalledPackageHistory history = new InstalledPackageHistory();
history.setContentServiceRequest(persistedRequest);
history.setPackageVersion(packageVersion);
history.setResource(resource);
history.setStatus(InstalledPackageHistoryStatus.BEING_DELETED);
history.setTimestamp(timestamp);
persistedRequest.addInstalledPackageHistory(history);
}
entityManager.persist(persistedRequest);