使用Spring在Hibernate中进行逆向工程 [英] reverse engineering in hibernate using spring

查看:57
本文介绍了使用Spring在Hibernate中进行逆向工程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

休眠可用于通过逆向工程生成所有DAO和休眠属性文件. 但是就弹簧依赖注入而言,它生成的DAO代码不合适.

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.

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

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

推荐答案

您应该使用通用DAO,在该DAO中,您只需要创建一个指定实体类的Subclass.或更现代的方法,例如 Spring Data JPA 或其前身

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).

因此,不值得花时间为DAO搜索和改进生成器方法.您可以在一个小时内手工写出60多个(如果您有通用的DAO)

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)

我没有太多时间搜索通用DAO的示例,因此这是我发现的最好的示例:@Repository,但没有注释@Component. -无论如何,该示例说明了通用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.

这篇关于使用Spring在Hibernate中进行逆向工程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆