I've used sql2java for java applications. But recently I needed something similar for PHP and used sql2java to generate, from a MySQL database.
Here's the sources of the templates I've used. Use it as you want.
2009-09-05 15:37:47 UTC in SQL to Java Code Generator