hibernate 的 SchemaExport 实现
来源:互联网 发布:mac 终端退出 bash 编辑:程序博客网 时间:2024/05/17 07:56
在 控制台 输出sql 语句:
new SchemaExport(new AnnotationConfiguration().configure()).create(false, true);
该类 SchemaExport 的方法的主要作用是 将表drop之后,再重新 create表 。
首先 SchemaExport 的构造函数 用到了 AnnotationConfiguration的 configure() 方法,
configure() 方法返回的两个参数 stream, 和 resource 都和 xml配置文件有关:
return doConfigure( stream, resource );
public SchemaExport(Configuration cfg) throws HibernateException {
this( cfg, cfg.getProperties() );
}
在 SchemaExport 构造的时候,存在 根据sql的方言来决定用哪种 sql 的 语法。
connectionHelper = new ManagedProviderConnectionHelper( props );
来获取到数据库的连接;
dropSQL = cfg.generateDropSchemaScript( dialect );
得到drop 表的sql 语句
createSQL = cfg.generateSchemaCreationScript( dialect );
得到 generate 表的sql 语句
public SchemaExport(Configuration cfg, Properties properties)
throws HibernateException {
dialect = Dialect.getDialect( properties );
Properties props = new Properties();
props.putAll( dialect.getDefaultProperties() );
props.putAll( properties );
connectionHelper = new ManagedProviderConnectionHelper( props );
dropSQL = cfg.generateDropSchemaScript( dialect );
createSQL = cfg.generateSchemaCreationScript( dialect );
format = PropertiesHelper.getBoolean( Environment.FORMAT_SQL, props );
}
另外注意一个 final class Environment ,其中的一些配置 如
public static final String USER ="hibernate.connection.username";
public static final String DIALECT ="hibernate.dialect"; 都是 从hibernate.cfg.xml获得的 。
还有注意一下:类Configuration 的 protected Map tables; 参数怎么初始化的:
这些参数都是 通过 DOM4j的方法 从 hibernate.cfg.xml获得的,具体是在 new AnnotationConfiguration().configure() 的 configure()方法中 。
- hibernate 的 SchemaExport 实现
- javaee之hibernate的schemaExport
- hibernate 5.x 的schemaExport的用法
- 使用hibernate的SchemaExport来创建数据库
- Hibernate 建表 SchemaExport
- Hibernate之SchemaExport
- 利用ant,hibernate的schemaexport自动生成数据库
- 利用 Hibernate 的 SchemaExport 根据对象建立数据库
- Hibernate 5.x版本中SchemaExport的用法
- hibernate使用SchemaExport生成对应的数据库表
- java hibernate SchemaExport 创建数据表
- SchemaExport对象的使用方法
- SchemaExport的使用
- SchemaExport
- SchemaExport
- Hibernate 基于注解的SessionFactory类的生成以及自动生成表SchemaExport类的
- hibernate中annotation方式SchemaExport无法生成表的原因(ORA-02261)
- hibernate中annotation方式SchemaExport无法生成表的原因(ORA-02261)
- 理解JavaScript原型
- jQuery - 获取内容和属性
- Java 项目Building之后发现的Blocker和Critical
- zoj1005
- mac osx下配置apache
- hibernate 的 SchemaExport 实现
- Scheduling (调度)相关
- 搭建适合IOS的HTTP Live Streaming直播系统
- poj1006 生理周期(中国剩余定理)
- 各种命令一日游
- Struts 2 Hello World Annotation Example
- javaweb学习总结(三十九)——数据库连接池
- .NET基础--if与else的匹配问题
- java static关键字