@Override
    public void update() {
        if (attributes.get(primaryKey) == null) {
            throw new NullPointerException("Can't update a non inserted object");
        }
        StringBuilder sb = new StringBuilder("UPDATE ");
        sb.append(tableName).append(" SET ");
        StringBuilder where = new StringBuilder(" WHERE ");
        where.append(getPrimaryKeyColumn()).append(" = ?");
        List<Object> values = new ArrayList<Object>();
        for (Map.Entry<String, Object> e : attributes.entrySet()) {
            String key = e.getKey();
            Object value = e.getValue();
            if (!(key.equals(primaryKey)) && !(value instanceof List) &&
                    !(value instanceof JavaRecord) && (value != null)) {
                sb.append(", ").append(key);
                sb.append(" = ");
                sb.append("?");
                values.add(value);
            }
        }
        String update = sb.toString().replaceFirst(",", "");
        update += where.toString();
        PreparedStatement smt = database.getPreparedStatement(update);
        int index = 0;
        try {
            for (index = 1; index <= values.size(); index++) {
                SQLUtil.addParameter(smt, index, values.get(index - 1));
            }
            SQLUtil.addParameter(smt, index, attributes.get(primaryKey));
            smt.execute();
            smt.close();
            smt = null;
        } catch (SQLException ex) {
            throw new SQLGeneratorException(ex.getMessage(), ex);
        }
    }