I need to make sure the new supplierpart I’m creating doesn’t exist. It is currently done like so
try {
entityManager.get(SupplierPartEntity.class,
new SupplierPartPK(supplierID, partID));
throw new CreateSupplierPartActionException("Supplier part record exists for " + supplierID
+ " / " + partID + ".");
} catch (final RecordNotFoundException e) {
/* supplier part not found - do nothing */
}
its worth noting entityManager will throw a record not found exception when get() would normally return null;
If by “less expensive” you mean “doesn’t hit the database”, then no, unless you keep a cache in memory of all existing primary keys. Other than that, the database is the only thing that knows them.