12. Given $x, y, z \in \mathbf{Z}$, and $x+y+z=3, x^{3}+y^{3}+z^{3}=3$, then $x^{2}+y^{2}+z^{2}=$
$$
\left\{\begin{array}{l}
x+y=3-z, \\
x^{3}+y^{3}=3-z^{3}
\end{array} \Rightarrow 3-z^{3}=(3-z)^{3}-3 x y(3-z) \Rightarrow x y=\frac{3 z^{2}-9 z+8}{3-z}\right. \text {. }
$$

Then $x, y$ are the two roots of the equation $u^{2}-(3-z) u+\frac{3 z^{2}-9 z+8}{3-z}=0$,
Thus $\Delta=(3-z)^{2}-4 \cdot \frac{3 z^{2}-9 z+8}{3-z}=(z-1)^{2}\left(1+\frac{8}{z-3}\right)$ is a perfect square, hence $z=1,4,-5$. At this point, $(x, y, z)=(1,1,1),(-5,4,4),(4,-5,4),(4,4,-5)$. Therefore, $x^{2}+y^{2}+z^{2}=3$ or 57.