hibernate基本配置

先加载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>
-->
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值