使用 spring 在 hibernate 中进行逆向工程

发布于 2025-01-07 01:52:04 字数 144 浏览 5 评论 0原文

Hibernate 可用于通过逆向工程生成所有 DAO 和 hibernate 属性文件。 但它生成的 DAO 代码对于 spring 依赖注入来说并不合适。

那么,我们如何利用hibernate逆向工程技术来生成基于依赖注入原理的spring bean呢?

Hibernate can be used to generate all DAO's and hibernate properties files using reverse engineering.
But the DAO code it generates is not appropriate in terms of spring dependency injection.

So, how can we use hibernate reverse engineering technique to generate spring beans based on principle of dependency injection?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热情消退 2025-01-14 01:52:04

您应该使用通用 DAO,其中您只需要创建一个指定实体类的子类。或者更现代的方法,例如 Spring Data JPA 或其前身 哈迪斯。然后,具体的 dao 不仅仅是一个空类(或者在 Spring Data JPA/Hades 的情况下是一个空接口)。

因此,不值得花时间为 DAO 搜索和调整生成器方法。您可以在一小时内手写其中六十多个(如果您有通用 DAO)

我没有那么多时间来搜索通用 DAO 的示例,所以这是我找到的最好的:http://www.codeproject.com/Articles/251166/The-Generic-DAO-pattern-in-Java-with-Spring-3-并且它至少有一个“错误” " concreate DAO 应该具有注释 @Repository,但不具有 @Component。 -- 无论如何,这个例子说明了我所说的通用 DAO 的含义。

You should use a generic DAO, where you only need to create a Subclass that specify the entity class. Or a more modern approach like Spring Data JPA or its predecessor Hades. Then the concrete dao in noting more than an empty class (or in case of Spring Data JPA/Hades an empty interface).

So it is not worth spending time in searching and addapting a generator approach for the DAOs. You can write more than sixty of them in one hour by hand (if you have a generic DAO)

I have not so much time to search for an example of an Generic DAO, so this is the best I found: http://www.codeproject.com/Articles/251166/The-Generic-DAO-pattern-in-Java-with-Spring-3-and it has at least one "mistake" the concreate DAO should have the annotation @Repository but not @Component. -- Anyway the example illustrate what I mean by generic DAO.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文