我正在使用eclipse(因为免费,不用看人脸色啊...), 还没装JBOSS tool(也没试过), 想试一个项目,用spring + hibernate + struts2.对于我这样的生手,用eclipse感觉配置文件多。
对于 hibernate 原来一直都是在spring中配置sessionnFactory --这是用myeclipse带来的习惯--, 现在用eclipse,没人帮管这些了,也不能逆向工程了。当然觉得很不方便。
对于项目自动管理,最近看上了maven,好处不多说了,也看到了 hibernate3-maven-plugin这个插件,希望能够帮我自动管理hibernate在spring中配置的麻烦事。
hibernate3-maven-plugin能做什么?
看一下它的goals表, 如下:
Goals available for this plugin:
Goal | Description |
---|---|
hibernate3:hbm2cfgxml | Generates hibernate.cfg.xml |
hibernate3:hbm2dao | Base class for the different hibernate3 goals based on the Ant tasks of hibernate tools. |
hibernate3:hbm2ddl | Generates database schema. |
hibernate3:hbm2doc | Generates HTML documentation for the database schema. |
hibernate3:hbm2hbmxml | Generates a set of hbm.xml files |
hibernate3:hbm2java | Generates Java classes from set of *.hbm.xml files |
hibernate3:hbmtemplate | Generic exporter that can be controlled by a user provided template or class. |
hibernate3:help | Display help information on hibernate3-maven-plugin. Call mvn hibernate3:help -Ddetail=true -Dgoal=<goal-name>to display parameter details. |
看起来还不错,功能还不少。
现在我有了一个appliacationContext.xml文件,我想干嘛?。。。如果我想先在代码中写好pojos, 想由这些pojos自动生成数据库架构。那试一下hbm2ddl吧。
我的applicationContext.xml如下
这样用hbm2ddl。。。。是不行的。因为hibernate3-maven-plugin(以下称hibernate3)不会去找sessionFactory这个bean,它如果找hibernate属性的配制,需要找一个src/main/resources/ 下一个叫database.properties的文件。里面定义了hibernate与数据库连接的属性。
而我们又想直接让它读appliactionContext.xml里面的sessionFactory的设置-- 好处是只维护一个文件--该怎么办呢?