code: @SuppressWarnings("unchecked")
      protected I getIdFromEntity(EntityManager em, Object entity, ResourceField idField) {
          Object pk = em.getEntityManagerFactory().getPersistenceUnitUtil().getIdentifier(entity);
          PreconditionUtil.verify(pk != null, "pk not available for entity %s", entity);
          if (pk != null && primaryKeyAttribute.getName().equals(idField.getUnderlyingName()) && idField.getElementType().isAssignableFrom(pk.getClass())) {
              return (I) pk;
          }
          return null;
      }
docs: Extracts the resource ID from the entity.
  By default it uses the entity's primary key if the field name matches the DTO's ID field.
  Override in subclasses if a different entity field should be used.
  
  @return the resource ID or <code>null</code> when it could not be determined