简体   繁体   English

如何正确使用Hibernate和Hibernate工具进行蚀?

[英]How to work correctly with Hibernate and Hibernate tools for eclipse?

I just started experimenting with Hibernate. 我刚刚开始尝试Hibernate。 My current approach for working with Hibernate is as follows: 我当前使用Hibernate的方法如下:

  1. Write cfg.xml and reveng.cfg.xml 编写cfg.xml和reveng.cfg.xml

  2. Use Hibernate tools for eclipse to generate POJO and hbm.xml files. 使用Hibernate工具进行Eclipse生成POJO和hbm.xml文件。

  3. Write my own DAO classes. 编写我自己的DAO类。 In the methods, add stored procedures calls to these classes using native SQL. 在这些方法中,使用本机SQL将存储过程调用添加到这些类。

I feel a bit uncomfortable regarding this approach. 对于这种方法,我感到有些不舒服。 Writing DAO classes is just a repetitive task that is always the same. 编写DAO类只是一个重复的任务,始终是相同的。 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. 我尝试使用Hiberante工具生成DAO类。 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? 使用Hibernate的正确方法是什么?

Writing DAO classes is just a repetitive task that is always the same. 编写DAO类只是一个重复的任务,始终是相同的。

Well, nothing forbids you writing a common superclass for all DAOs. 嗯,没有什么可以阻止您为所有DAO编写一个通用的超类。 You can look at this example ( AbstractJpaDAO , bottom of the article) of how it is possible. 您可以看一下如何实现这个示例AbstractJpaDAO ,本文的底部)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM