Hello,
I spent a long, long time today sorting out how to use Hibernate, hbm2java (generating Annotated POJOs), and the hibernatetools Ant tasks against MySQL. In my travels I found that my problems weren't unique to me, so in an effort to help future generations, I am posting this to help people. Hopefully Google indexes this place.
This is a sort of 'hello world' for the mentioned technologies, and doesn't do anything interesting (unless you consider "working" to be interesting).
First: I put all my source code here:
http://code.google.com/p/sketching-games/source/browse/#svn/trunk/schmoo
You may browse or check it out if you want.
Now, the README with the snarky bits cut out.
This source code might help you in your quest to generate Java objects
directly from a database schema. It is essentially "Hello, World" for
using the following things in a sort of belligerent cooperation:
- mysql
- hibernatetool (the Hibernate Ant Task)
- hbm2java (Generate Java code based on DB Schema(s))
- using hbm2java to generation Annotated Java code (rather than XML
files)
- The funky and disfunctional relationship between them, starring
hibernate.cfg.xml.
-*- =-------= -*-
** Easy steps to Hibernation Zen! This took me about two days of **
** headbanging so you don't have to. **
------
(1) Read this file. So far so good.
(2) Create the database using webapps/config/create_db.sql:
$ mysql -u root -p < webapps/config/create.db.sql
(3) Generate the plain old Java objets (POJOs, as they say):
$ ant hiber
(4) Compile the source code (my code in org.six11.schmoo.*, and the
generated stuff in schmoo.*):
$ ant compile
(5) Run it!
$ ./run
$ ./run Bob Sue Franklin Patricia
$ ./run Robokitty Karolina