throw new DatabaseOperationException("Error while inserting into the database", ex);
throw new DatabaseOperationException("Error while inserting into the database: " + ex.getMessage(), ex);
    public void insert(Connection connection, Database model, DynaBean dynaBean) throws DatabaseOperationException    {        SqlDynaClass      dynaClass       = model.getDynaClassFor(dynaBean);        SqlDynaProperty[] properties      = getPropertiesForInsertion(model, dynaClass, dynaBean);        Column[]          autoIncrColumns = getRelevantIdentityColumns(model, dynaClass, dynaBean);        if ((properties.length == 0) && (autoIncrColumns.length == 0))        {            _log.warn("Cannot insert instances of type " + dynaClass + " because it has no usable properties");            return;        }        String insertSql        = createInsertSql(model, dynaClass, properties, null);        String queryIdentitySql = null;        if (_log.isDebugEnabled())        {            _log.debug("About to execute SQL: " + insertSql);        }        if (autoIncrColumns.length > 0)        {            if (!getPlatformInfo().isLastIdentityValueReadable())            {                _log.warn("The database does not support querying for auto-generated column values");            }            else            {                queryIdentitySql = createSelectLastInsertIdSql(model, dynaClass);            }        }        boolean           autoCommitMode = false;        PreparedStatement statement      = null;        try        {            if (!getPlatformInfo().isAutoCommitModeForLastIdentityValueReading())            {                autoCommitMode = connection.getAutoCommit();                connection.setAutoCommit(false);            }            statement = connection.prepareStatement(insertSql);            for (int idx = 0; idx < properties.length; idx++ )            {                setObject(statement, idx + 1, dynaBean, properties[idx]);            }            int count = statement.executeUpdate();            if (count != 1)            {                _log.warn("Attempted to insert a single row " + dynaBean +                          " in table " + dynaClass.getTableName() +                          " but changed " + count + " row(s)");            }        }        catch (SQLException ex)        {            throw new DatabaseOperationException("Error while inserting into the database", ex);        }        finally        {            closeStatement(statement);        }        if (queryIdentitySql != null)        {            Statement queryStmt       = null;            ResultSet lastInsertedIds = null;            try            {                if (getPlatformInfo().isAutoCommitModeForLastIdentityValueReading())                {                    // we'll commit the statement(s) if no auto-commit is enabled because                    // otherwise it is possible that the auto increment hasn't happened yet                    // (the db didn't actually perform the insert yet so no triggering of                    // sequences did occur)                    if (!connection.getAutoCommit())                    {                        connection.commit();                    }                }                queryStmt       = connection.createStatement();                lastInsertedIds = queryStmt.executeQuery(queryIdentitySql);                lastInsertedIds.next();                for (int idx = 0; idx < autoIncrColumns.length; idx++)                {                    // we're using the index rather than the name because we cannot know how                    // the SQL statement looks like; rather we assume that we get the values                    // back in the same order as the auto increment columns                    Object value = getObjectFromResultSet(lastInsertedIds, autoIncrColumns[idx], idx + 1);                    PropertyUtils.setProperty(dynaBean, autoIncrColumns[idx].getName(), value);                }            }            catch (NoSuchMethodException ex)            {                // Can't happen because we're using dyna beans            }            catch (IllegalAccessException ex)            {                // Can't happen because we're using dyna beans            }            catch (InvocationTargetException ex)            {                // Can't happen because we're using dyna beans            }            catch (SQLException ex)            {                throw new DatabaseOperationException("Error while retrieving the identity column value(s) from the database", ex);            }            finally            {                if (lastInsertedIds != null)                {                    try                    {                        lastInsertedIds.close();                    }                    catch (SQLException ex)                    {                        // we ignore this one                    }                }                closeStatement(statement);            }        }        if (!getPlatformInfo().isAutoCommitModeForLastIdentityValueReading())        {            try            {                // we need to do a manual commit now                connection.commit();                connection.setAutoCommit(autoCommitMode);            }            catch (SQLException ex)            {                throw new DatabaseOperationException(ex);            }        }    }