Monday, November 17, 2008

    Hibernate Musings

    So, I'm working my way through this tutorial on hibernate. It basically takes you through creating a basic (and trivial) Hibernate project, all the way to the point where you create the database and put info into it, then take it out.

    Wait, did I just say "create the database"? That I did. I think this is the coolest feature in Hibernate that I've come across so far. The work flow basically works like this: First, you create your POJO bean which will hold a record. Then, you create a mapping file which will map the properties of the bean onto a table in the database. Next, you set a special property in your hibernate.cfg.xml file (called to "create". Finally, you create some utility classes that drive Hibernate.

    Set up an ant task to do something (in my case, I stored a record) with the database and run it.

    On start up Hibernate will create the database using the mapping files. The more mapping files you have, the more tables will be created. I still don't know if you can create multiple tables from one mapping, but the ability to create a database based off of POJO beans is some kind of powerful and is a feature that I will hopefully use to a great degree in order to get around some of my relative inexperience with database design.

    No comments: