When a finitely generated ideal is contained in a union of maximal ideals For a commutative ring $R$ with 1, it is well known that if an ideal is contained in the union of all maximal ideals, then it contained in one of them. I want to know why the following is true or  is there any condition on $R$ that it is true:
Let $I$ be a finitely generated ideal, and let $\{\frak{m}_i\}$ be an  infinite family of maximal ideals with $I\subseteq \cup_i\frak{m}_i$. Then there exists $j$ such that $I\subseteq \frak{m}_j$. 
 A: In the example in my comment, the ideal $I$ is not finitely generated.  Here is an example with $I$ finitely generated (this example also illustrates why the Prime Avoidance Theorem only holds for finite sets of primes).  Let $A$ be the commutative ring $k[x,y,z]$ with $k$ a field.  Let $M$ be the ideal $\langle x,y,z\rangle$.  Let $\mathcal{P}$ be the set of all height two primes $\mathfrak{p}$ of $A$ that are contained in the ideal $M$, i.e., $\mathcal{P}$ indexes the irreducible curves in $\mathbb{A}^3$ that contain the origin.  For each $\mathfrak{p}$ in $\mathcal{P}$, denote by $A_{\mathfrak{p}}$ the corresponding localization with maximal ideal $\mathfrak{p}A_{\mathfrak{p}}$.  Let $A_{\mathcal{P}}$ denote the infinite product, $$ A_{\mathcal{P}} = \prod_{\mathfrak{p}\in \mathcal{P}} A_{\mathfrak{p}},$$ together with the diagonal ring homomorphism, $$\Delta: A \to \prod_{\mathfrak{p}\in \mathcal{P}}A_{\mathfrak{p}}.$$  Denote by $R$ the subring of $A_{\mathcal{P}}$ generated by $\text{Image}(\Delta)$ and the ideal $F$ of all elements in the product ring that have zero components for all but finitely many $\mathfrak{p}\in \mathcal{P}$.  Since every homomorphism $A\to A_{\mathfrak{p}}$ is injective, the induced ring homomorphism, $$\rho: A \to R/F,$$ is an isomorphism.  
Denote by $I$ the ideal of $R$ generated by $\Delta(J)$, i.e., the finitely generated ideal $\langle \Delta(x), \Delta(y) \rangle$.  For every $\mathfrak{p}$ in $\mathcal{P}$, projection on the corresponding factor ring, $$\pi_{\mathfrak{p}}:R \to A_{\mathfrak{p}},$$ is a surjective ring homomorphism.  Thus the inverse image ideal is a maximal ideal, $$ \mathfrak{m}_{\mathfrak{p}} = \pi_{\mathfrak{p}}^{-1}\left( \mathfrak{p}A_{\mathfrak{p}}\right).$$ Via $\rho$, every element of $R$ has a unique decomposition as $\rho(a) + b$ with $a\in A$ and with $b\in F$.  In particular, every element of $I$ is of the form $\rho(a)+b$ with $a\in M$.  The element $a$ is contained in infinitely many height two primes $\mathfrak{p}$ that are contained in $M$, i.e., every hypersurface in $\mathbb{A}^3$ that contains the origin contains infinitely many irreducible curves that contain the origin.  Thus, there exists a height two prime $\mathfrak{p}$ in $\mathcal{P}$ containing $a$ and such that the component of $b$ in the corresponding factor $A_{\mathfrak{p}}$ is zero.  Thus, $\rho(a)+b$ is contained in $\mathfrak{m}_{\mathfrak{p}}$.  So $I$ is contained in the union of the maximal ideals $\mathfrak{m}_{\mathfrak{p}}$ for all $\mathfrak{p}\in \mathcal{P}$.  
On the other hand, for every finite set of height two primes $\mathfrak{p}$ in $\mathcal{P}$, there exists $a\in M$ such that $a$ is contained in none of these finitely many primes, i.e., for every finite set of irreducible curves containing the origin, there exists an irreducible surface containing the origin and containing none of the curves.  Thus $\rho(a)$ is not contained in the union of the finitely many corresponding maximal ideals $\mathfrak{m}_{\mathfrak{p}}$.  
