reverse engineering in hibernate using spring

China☆狼群 提交于 2019-12-23 02:07:19

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/9359879/reverse-engineering-in-hibernate-using-spring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!