`
kevin.wang
  • 浏览: 243564 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

hibernate基本配置

    博客分类:
  • Web
阅读更多
先加载hibernate.properties,后加载hibernate.cfg.xml
<hibernate-configuration>
	<session-factory>
		<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
		<property name="hibernate.connection.url">jdbc:mysql://localhost/spring_hibernate_1</property>
		<property name="hibernate.connection.username">root</property>
		<property name="hibernate.connection.password">bjpowernode</property>
		<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
		<property name="hibernate.show_sql">true</property>
		<property name="hibernate.hbm2ddl.auto">update</property>
		
		<property name="hibernate.current_session_context_class">thread</property>
		<!-- 
		<property name="hibernate.current_session_context_class">jta</property>
 		-->
		<mapping resource="com/bjpowernode/usermgr/domain/User.hbm.xml"/>
		<mapping resource="com/bjpowernode/usermgr/domain/Log.hbm.xml"/>
	</session-factory>
</hibernate-configuration>


============================
hibernate.hbm2ddl.auto

它包含4个属性:
create : 会根据你的model类来生成表,但是每次运行都会删除上一次的表,重新生成表,哪怕2次没有任何改变

create-drop : 根据model类生成表,但是sessionFactory一关闭,表就自动删除
update : 最常用的属性,也根据model类生成表,即使表结构改变了,表中的行仍然存在,不会删除以前的行

validate : 只会和数据库中的表进行比较,不会创建新表,但是会插入新值
==================================
本地事务
<property name="hibernate.current_session_context_class">thread</property>
JTA事务
<!--
<property name="hibernate.current_session_context_class">jta</property>
-->


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics