Hibernate新建表的代码实现。请高手指点迷津。在线等。。。 现在做一个WEB应用系统,数据库的相关操作都是Hibernate实现的,但是业务要求能够在程序运行的时候新建表。比如説我在进行项目登陆的时候,要新建一个“项目”表。请各位高手指点一下,我该怎么实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <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> 可以实现的,你把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视频教程 <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> 我是路过,看看行不行啊就是利用程序动态的生成配置文件,比如你需要新建一个TBL_01的话,就动态生成一个配置文件的信息,然后再利用hibernate中的工具包像3楼上的代码,来创建表。只是需要修改一下读取的配置文件路径就可以了。 求一个用MVC模式开发的登陆注册小程序 谁给我解释一下!!! 我的服务器是linux+jboss4.0 我改端口后 域名访问不了怎么办呢 怎么让jsp弹出对话框? 连接数据库的问题 写在页面上可以连接 写在后台不能连接 JSP 中怎么把数据导到 EXCEL 中 ,请高人指点!!急 急 急 在线等!!! struts动态包含问题 紧急求救:连informix中文显示乱码问题。。 赐教重定向的问题 Javamail写的收发邮件程序,为何收到的是乱码? 关于tomcat 启动 出现错误 问题 急 高分寻jsp虚拟主机(小型,稳定,低价)
<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>
public static void main(String []args){
Configuration cfg = new Configuration().configre();
SchemaExport export = new SchemaExport(cfg);
export.create(true,true);
}
}建议你去看下北京尚学堂的hibernate视频教程
<property name="hibernate.hbm2ddl.auto">create </property>
<mapping resource="cn/xx/xx/xx/xx/xx/xx.hbm.xml" />
</hibernate-configuration>
</session-factory>
就是利用程序动态的生成配置文件,比如你需要新建一个TBL_01的话,就动态生成一个配置文件的信息,然后再
利用hibernate中的工具包像3楼上的代码,来创建表。只是需要修改一下读取的配置文件路径就可以了。