int delete(Db db, Object obj) {
		if (!StringUtils.isNullOrEmpty(viewTableName)) {
			throw new IciqlException("Iciql does not support deleting rows from views!");
		}
		if (primaryKeyColumnNames == null || primaryKeyColumnNames.size() == 0) {
			throw new IllegalStateException("No primary key columns defined for table " + obj.getClass()
					+ " - no update possible");
		}
		SQLStatement stat = new SQLStatement(db);
		StatementBuilder buff = new StatementBuilder("DELETE FROM ");
		buff.append(db.getDialect().prepareTableName(schemaName, tableName));
		buff.resetCount();
		Object alias = Utils.newObject(obj.getClass());
		Query<Object> query = Query.from(db, alias);
		boolean firstCondition = true;
		for (FieldDefinition field : fields) {
			if (field.isPrimaryKey) {
				Object fieldAlias = field.getValue(alias);
				Object value = field.getValue(obj);
				if (field.isPrimitive) {
					fieldAlias = query.getPrimitiveAliasByValue(fieldAlias);
				}
				if (!firstCondition) {
					query.addConditionToken(ConditionAndOr.AND);
				}
				firstCondition = false;
				query.addConditionToken(new Condition<Object>(fieldAlias, value, CompareType.EQUAL));
			}
		}
		stat.setSQL(buff.toString());
		query.appendWhere(stat);
		IciqlLogger.delete(stat.getSQL());
		return stat.executeUpdate();
	}