EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, entityName); EODatabaseContext dbContext = EODatabaseContext.registeredDatabaseContextForModel(entity.model(), ec); NSDictionary primaryKey = null; try { dbContext.lock(); EOAdaptorChannel adaptorChannel = dbContext.availableChannel().adaptorChannel(); if (!adaptorChannel.isOpen()) adaptorChannel.openChannel(); NSArray arr = adaptorChannel.primaryKeysForNewRowsWithEntity(1, entity); if (arr != null) primaryKey = (NSDictionary) arr.lastObject(); else log.warn("Could not get primary key for entity: " + entityName + " exception"); dbContext.unlock(); } catch (Exception e) { dbContext.unlock(); log.error("Caught exception when generating primary key for entity: " + entityName + " exception: " + e, e); } return primaryKey;
EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, entityName); EODatabaseContext dbContext = EODatabaseContext.registeredDatabaseContextForModel(entity.model(), ec); NSDictionary primaryKey = null; dbContext.lock(); try { EOAdaptorChannel adaptorChannel = dbContext.availableChannel().adaptorChannel(); if (!adaptorChannel.isOpen()) { adaptorChannel.openChannel(); } NSArray arr = adaptorChannel.primaryKeysForNewRowsWithEntity(1, entity); if (arr != null) { primaryKey = (NSDictionary) arr.lastObject(); } else { log.warn("Could not get primary key for entity: " + entityName + " exception"); } } catch (Exception e) { log.error("Caught exception when generating primary key for entity: " + entityName + " exception: " + e, e); } finally { dbContext.unlock(); } return primaryKey;
    public static NSDictionary primaryKeyDictionaryForEntity(EOEditingContext ec, String entityName) {        EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, entityName);        EODatabaseContext dbContext = EODatabaseContext.registeredDatabaseContextForModel(entity.model(), ec);        NSDictionary primaryKey = null;        try {            dbContext.lock();            EOAdaptorChannel adaptorChannel = dbContext.availableChannel().adaptorChannel();            if (!adaptorChannel.isOpen()) adaptorChannel.openChannel();            NSArray arr = adaptorChannel.primaryKeysForNewRowsWithEntity(1, entity);            if (arr != null)                primaryKey = (NSDictionary) arr.lastObject();            else                log.warn("Could not get primary key for entity: " + entityName + " exception");            dbContext.unlock();        } catch (Exception e) {            dbContext.unlock();            log.error("Caught exception when generating primary key for entity: " + entityName + " exception: " + e, e);        }        return primaryKey;    }