现在做一个WEB应用系统,数据库的相关操作都是Hibernate实现的,但是业务要求能够在程序运行的时候新建表。比如説我在进行项目登陆的时候,要新建一个“项目”表。请各位高手指点一下,我该怎么实现?

解决方案 »

  1.   


    <hibernate-configuration><session-factory>
    <property name="hibernate.hbm2ddl.auto">create</property>
    <mapping resource="cn/xx/xx/xx/xx/xx/xx.hbm.xml" />
    </hibernate-configuration>
    </session-factory>
      

  2.   

    可以实现的,你把hibernate的配置文件配好,还有po的映射文件配好,然后通过以下代码就可以自动创建表public class ExportDataBase{
         public static void main(String []args){
            Configuration cfg = new Configuration().configre();
            SchemaExport export = new SchemaExport(cfg);
            export.create(true,true);
         }
    }建议你去看下北京尚学堂的hibernate视频教程
      

  3.   

    <hibernate-configuration> <session-factory> 
    <property name="hibernate.hbm2ddl.auto">create </property> 
    <mapping resource="cn/xx/xx/xx/xx/xx/xx.hbm.xml" /> 
    </hibernate-configuration> 
    </session-factory>
      

  4.   

    我是路过,看看行不行啊
    就是利用程序动态的生成配置文件,比如你需要新建一个TBL_01的话,就动态生成一个配置文件的信息,然后再
    利用hibernate中的工具包像3楼上的代码,来创建表。只是需要修改一下读取的配置文件路径就可以了。