Why don't people become immune to bacteria?

One of the common pearls of wisdom in the big world of Sex Education is that if you have a bacterial STD, and pass it along to your partner, then get treated, your partner can give it back to you and you are then reinfected and that you BOTH need to get treated.

Why don’t we become immune to these infections like we become immune to a cold virus? I can think of a few possibilities:

  1. You only become immune if your immune system successfully fights off the infection on its own. By using antibiotics, you prevented your body from developing the right defenses.
  2. The bacteria has mutated by the time it comes back, and pre-existing antibodies don’t detect it.
  3. You can’t become immune to bacteria through exposure (then what about the Bacterial Meningitis vaccine?)

You can become immune to some bacteria but not others. Neisseria gonorrhoeae exhibits antigen variation (I think it’s due to random DNA rearrangement which code for its pilus) so the antibodies you have to one gonorrhea infection will not be effective against another, and there’s no vaccine. Neisseria meningitidis, on the other hand, does not exhibit the same kind of antigenic variation, so you can vaccinate and have lasting immunity against it. Pertussis is another example of a bacterial infection which is prevented by vaccination.