I have encountered the same problem.
A solution that must be tested is to call the "isValid(int timeout)" method from the java.sql.Connection
Or set autoreconnect in mysql: http://dev.mysql.com/doc/refman/5.0/en/auto-reconnect.html
Or change the timeout in mysql (default = 8 hours): http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_wait_timeout
EDIT: but I think that the best pratice is to open the connection during a transaction and then close it directly after that.