Archive for hibernate

hibenate.hbm2ddl.auto 屬性解釋

hibernate配置属性中, hibernate.hbm2ddl.auto可以帮助你实现正向工程,

即由java代码生成数据库脚本,进而生成具体的表结构.
在hibernate.cfg.xml中:

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

它包含4个属性:

  • create : 会根据你的model类来生成表,但是每次运行都会删除上一次的表,重新生成表,哪怕2次没有任何改变
  • create-drop : 根据model类生成表,但是sessionFactory一关闭,表就自动删除
  • update : 最常用的属性,也根据model类生成表,即使表结构改变了,表中的行仍然存在,不会删除以前的行
  • validate : 只会和数据库中的表进行比较,不会创建新表,但是会插入新值

文章來源:

http://42087743.javaeye.com/blog/219988

發表迴響

找尋目前mapping到的方法 getClassMappings()

Iterate the entity mappings
Returns:
Iterator of the entity mappings currently contained in the configuration.

出處:

https://www.hibernate.org/hib_docs/v3/api/org/hibernate/cfg/Configuration.html#getClassMappings()

發表迴響

Follow

Get every new post delivered to your Inbox.