Hibernate通过Bean生成表的方法
来源:互联网 发布:苏州中国软件名城 编辑:程序博客网 时间:2024/06/11 03:32
step1:首先创建 hibernate.cfg.xml文件,里面的代码就不多解释
<?xml version='1.0' encoding='utf-8'?><!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"><hibernate-configuration> <session-factory> <property name="connection.username">root</property> <property name="connection.password">1234</property> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql:///studentcourse</property> <property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property> <property name="show_sql">true</property> <property name="format_sql">true</property> <property name="hbm2ddl.auto">update</property> <mapping resource="com/bzu/entity/Adminer.hbm.xml"/> <mapping resource="com/bzu/entity/Course.hbm.xml"/> <mapping resource="com/bzu/entity/Student.hbm.xml"/> </session-factory></hibernate-configuration>
step2:保证bean、bean.hbm.xml 的完整性(这里不多介绍)
step3:编写 ExportDB 类(也就是一个执行方法)
package com.bzu.entity;import org.hibernate.cfg.Configuration;import org.hibernate.tool.hbm2ddl.SchemaExport;public class ExportDB { public static void main(String[] args) { // 读取配置文件 Configuration cfg = new Configuration().configure(); // 创建SchemaExport对象 SchemaExport export = new SchemaExport(cfg); // 创建数据库表 export.create(true, true); }}
step4:执行 main 方法即可自动创建表
0 0
- Hibernate通过Bean生成表的方法
- hibernate通过实体生成表
- MyEclipse6.5通过Hibernate逆向工程生成的映射文件和pojo(bean)不在相同目录解决
- 通过Bean工厂创建bean实例的几种方法
- 通过Hibernate的hbm.xml文件生成数据库表
- 通过Hibernate的hbm.xml文件生成数据库表
- hibernate通过annotation自动生成数据库表
- 通过hibernate配置文件无法生成表结构
- spring(12) Spring的通过工厂方法配置Bean
- Spring通过实现getBean方法获得Bean的实例
- 怎么通过带参数的构造方法实例化Bean
- 通过切面为Spring bean添加新的方法
- Hibernate 系统自动生成数据库表的两种方法
- from表单提交给action自动生成bean的方法
- Spring Boot生成bean的二种方法
- Spring Boot生成bean的二种方法
- spring管理bean的生命周期与spring通过工厂方法配置bean
- 通过Annotation注解来生成Bean
- 飞思卡尔MC9S12系列单片机地址影射以及分页问题
- 数据结构-二叉树的线索化
- java中list和arraylist的区别
- linux使用yum命令产生的进程锁问题
- 数组去重
- Hibernate通过Bean生成表的方法
- 编程技巧,数组覆盖
- 求n!的位数以及求n!具体的值(C or C++)
- 有向图强连通判断C/C++
- 排序算法c/c++
- python爬虫
- ext4_register_li_request
- Servlet的地址,跳转
- 查找元素出现的位置