atitit.提升开发效率---MDA 软件开发方式的革命(3)----自己主动化建表

atitit.提升开发效率---MDA 软件开发方式的革命(3)----自己主动化建表

1. 建模在后自己主动建表 1

1. 传统上,须要首先建表,在业务编码.. 1

2. 模型驱动建表---很多其它简化法是在建模在后自己主动建表 1

2. 自己主动建表的原理: 1

3. 自己主动建表工具::hibernate.hbm2ddl Hibernate4.1 2

4. hbm2ddl最佳实践 2

3. hibernate.hbm2ddl.auto 2

5. Java语句运行 3

6. 使用Ant 运行hbm2ddl 3

7. QA 4

4. Table 'gialenweixin.gv_material' doesn't exist 4

5. hibernate Attribute "value" must be declared for element type "property". 4

8. 參考 4

1. 建模在后自己主动建表

1. 传统上,须要首先建表,在业务编码..

1.  摘要:非常多程序仅仅有源码。没有配套的数据库sql语句。这样就非常不easy演示或操作

2. 模型驱动建表---很多其它简化法是在建模在后自己主动建表

作者:: 老哇的爪子 Attilax 艾龙,  EMAIL:1466519819@qq.com

转载请注明来源: http://blog.csdn.net/attilax

2. 自己主动建表的原理:

Sql生成:读取注解,生成sql,运行sql

3. 自己主动建表工具::hibernate.hbm2ddl 跟Hibernate4.1

配好的hibernate库和数据库的连接驱动。

数据库必须连接上。能够没有表。

Hibernate4.1已经能够自己主动建表,所以开发时仅仅须要自己开发类然后配置好就OK。不须要考虑怎么建表

Hibernate配置文件生成sql文件

4. hbm2ddl最佳实践

update仅仅是更新表结构,但不能生成..所以。你能够先用create属性。然后执行一次后改用update。以免数据丢收

3. hibernate.hbm2ddl.auto

<property name="hibernate.hbm2ddl.auto" value="update" />

update: 
最经常使用的属性,第一次载入hibernate时依据model类会自己主动建立起表的结构(前提是先建立好数据库)。以后载入 hibernate时依据 model类自己主动更新表结构,即使表结构改变了但表中的行仍然存在不会删除曾经的行。要注意的是当部署到server后。表结构是不会被立即建立起来的,是要等 应用第一次执行起来后才会。 
validate : 
每次载入hibernate时,验证创建数据库表结构。仅仅会和数据库中的表进行比較,不会创建新表,可是会插入新值

hbm2ddl 工具是个jar

hbm2ddl

5. Java语句运行

config = new Configuration()

                .configure(new File("src/hibernate.cfg.xml"));

 SchemaExport schemaExport = new SchemaExport(config);

        schemaExport.setOutputFile("E:\sql1.txt");

        schemaExport.create(true, false);

        System.out.println("Table created.");

6. 使用Ant 运行hbm2ddl

·   <!-- create ddl form  *.hbm.xml -->  

·     <target name="hbm2ddl"    

·             description="Generate DB schema from the O/R mapping files">  

·         <taskdef name="hbm2ddl"   

·             classname="org.hibernate.tool.ant.HibernateToolTask"   

·             classpathref="libraries"/>  

·         <hbm2ddl destdir="${ddlsqldir}">  

·             <configuration configurationfile="${basedir}/hibernate.cfg.xml" />   

·             <hbm2ddl export="true" console="false" create="true" update="false" drop="false" outputfilename="ddl.sql"/>   

·         </hbm2ddl>     

·     </target>  

·   

7. QA

4.  Table 'gialenweixin.gv_material' doesn't exist

update仅仅是更新表结构。但不能生成..所以,你能够先用create属性,然后执行一次后改用update,以免数据丢收

5. hibernate Attribute "value" must be declared for element type "property".

<property name="hibernate.hbm2ddl.auto"  value=update />

Change to...  Hb ver  hb4

<property name="hibernate.hbm2ddl.auto"   >update</property>

8. 參考

hibernate4.0+版本号和3.0+版本号的差别总结_xidianzxm_新浪博客.htm

Hibernate利用@DynamicInsert@DynamicUpdate生成动态SQL语句 - QuantSeven - 博客园.htm

Hibernate配置文件生成sql文件_zjha4148_新浪博客.htm

原文地址:https://www.cnblogs.com/yxysuanfa/p/6738292.html