How to work correctly with Hibernate and Hibernate tools for eclipse?

578 views Asked by At

I just started experimenting with Hibernate. My current approach for working with Hibernate is as follows:

  1. Write cfg.xml and reveng.cfg.xml

  2. Use Hibernate tools for eclipse to generate POJO and hbm.xml files.

  3. 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?

1

There are 1 answers

0
mindas On

Writing DAO classes is just a repetitive task that is always the same.

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.