@Override public void create(User user) { try (Connection connection = getConnection()) { try (PreparedStatement statement = connection.prepareStatement(CREATE)) { statement.setString(1, user.getLogin()); statement.setString(2, passwordEncoder.encode(user.getPassword())); statement.setInt(3, user.getPersonality().getId()); statement.executeUpdate(); } try (PreparedStatement statement = connection.prepareStatement(CREATE_USER_ROLE)) { for (Role role : user.getRoles()) { statement.setInt(1, user.getId()); statement.setInt(2, role.getId()); statement.executeUpdate(); } } } catch (SQLException e) { processException(e); } }