A mass $m$ is attached to a vertical spring of elastic constant $K$ and length $L$. The spring is supposed to be of negligible mass. Due to the attached mass $m$ the spring reaches a new equilibrium configuration at a length $L+x$.
According to Hooke's law the spring elongation is given by $x= \frac{mg}{K}$, since the weight has to be equilibrated by the elastic force.
On the other hand, by applying the principle of energy conservation, the initial gravitational potential energy is transformed in elastic potential energy say $mgh$ is transformed in $\frac{1}{2}Kx^2+mg(h-x)$ which leads to $mgx= \frac{1}{2}Kx^2$. The spring elongation is then $x= \frac{2mg}{K}$. It seems a contradiction.
What is wrong in these arguments?