首页 > 代码库 > hibernate入门

hibernate入门

***********

1,hibernate.hbm.xml,

表与对象的映射规律

2,hibernate.cfg.xml

hibernate的配置文件

比如还有那些其他资源文件,在什么地方

hibernate将要映射成那种数据库的语言

hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.hbm2ddl.auto=update <!--是否需要根据映射源数据生产数据表结构 -->
hibernate.show_sql=true
hibernate.format_sql=false

注:

hibernate.hbm2ddl.auto可以取值:

create-drop:每次创建,关闭时删除

create:每次创建前删除,关闭时不删除(测试时方便)

update:每次发现有不同,则更新

validate:每次发现有不同,不会更新,而是报错,所以更安全

 

连接数据库的信息,如驱动名,url,username,password

3,hibernate默认把自动提交事务关闭了

所以要显式提交

tx=s.beginTransaction()

tx.commit();

4,mysql默认的engine=myisam

不支持事务,不能回滚

而InnoDB支持事务,可以回滚

5,

 

 

 

***********

hibernate入门