Hibernate - POJO and HBM file creation best practice
By Mahipalsinh Rana on Aug 07, 2008
Recently I was working on Hibernate and created a number of POJO and their corresponding hbm file. I am using Netbeans (who has support for Hibernate plugin , real helpful , http://netbeans.org )
Certain best practice I would like to make work more interesting.
- Keep table name and POJO name same.
ex. Create new Java Class i.e Person , Use hibernate plugin to create .hbm file , Give same name as Class file , Select Person as class name on next screen.
This will create .hbm file with name as Person , no need to provide table attribute. Hibernate will create table with same name.
This aovides unnecessary complexities in distinguice table name and class name
- Keep POJO variable name same as Field name
Do no mention Column attribute while declaring <Property> in .hbm file. Hibernate will create column with same name.
- Try to keep ID as primaray key for all the Tables where possible. Less to remember and more time to figure out solution to problem on hand.
- How can I forgot my Dear I18n. There is nothing much as long as you make sure that created Database has UTF-8 encoding.
- One more point , Certain tables are used to keep default list. If the list compoment is localizable make sure you take care of fetching localized values from proper resource bundle before publishing to User Interface.
Resources :More will follow as I learn more ... enjoy your life ... n keep doing innovation ... only way to survive ...