I just started experimenting with Hibernate. My current approach for working with Hibernate is as follows:
Write cfg.xml and reveng.cfg.xml
Use Hibernate tools for eclipse to generate POJO and hbm.xml files.
Write my own DAO classes. In the methods, add stored procedures calls to these classes using native SQL.
I feel a bit uncomfortable regarding this approach. Writing DAO classes is just a repetitive task that is always the same. The only changes are the names and parameters of the stored procedures. This can be automated by looking into the database and looking at the stored procedures inside. Generaly I feel there is a lot of code repetition smell.
I tried generating DAO classes using Hiberante tools. It is not satisfactory as well. The classes contain code that I don't need, and lack the stored procedure calls.
What am I missing here? What is the correct methodology for working with Hibernate?
Well, nothing forbids you writing a common superclass for all DAOs. You can look at this example (
AbstractJpaDAO
, bottom of the article) of how it is possible.