/**
   * Creates a new type with the primary key. Does not add the type to the database.
   *
   * @param typeId the primary key for the new type
   * @return the new type
   */
  @Override
  public Type create(long typeId) {
    Type type = new TypeImpl();

    type.setNew(true);
    type.setPrimaryKey(typeId);

    return type;
  }
  @Override
  public Type updateImpl(Type type) {
    type = toUnwrappedModel(type);

    boolean isNew = type.isNew();

    Session session = null;

    try {
      session = openSession();

      if (type.isNew()) {
        session.save(type);

        type.setNew(false);
      } else {
        type = (Type) session.merge(type);
      }
    } catch (Exception e) {
      throw processException(e);
    } finally {
      closeSession(session);
    }

    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

    if (isNew) {
      finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    }

    entityCache.putResult(
        TypeModelImpl.ENTITY_CACHE_ENABLED, TypeImpl.class, type.getPrimaryKey(), type, false);

    type.resetOriginalValues();

    return type;
  }