Hibernate学习随记

来源:互联网 发布:form表单提交到数据库 编辑:程序博客网 时间:2024/06/08 00:06

hibernate是对jdbc使用的框架


工作流程

   事务(transaction)
   会议(session)
      1、获得当前会议2、开启事务3、执行对数据库的操作4、提交事务,捕获异常5、关闭事务


对mysql语句的封装

    hibernate对大部分mysql进行了封装,增删改查可以直接通过调用session的方法进行



//hibernate的一般配置

<hibernate-configuration>
   <session-factory>
    <property name="connection.username">username</property> 
    <property name="connection.password">password</property>
   <property name="connection.driver_class">com.mysql.jdbc.Driver</property> //数据库驱动
   <property name="connection.url">jdbc:mysql:///test?useUnicode=true&amp;characterEncoding=UTF-8</property> //数据库编码
   <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
   <property name="show_sql">true</property>   //控制台是否显示sql操作语句
   
   <property name="fromat_sql">true</property>
    <property name="hbm2ddl.auto">update</property>
     <property name="hibernate.current_session_context_class">thread</property> 
     
    <mapping resource="entity/Users.hbm.xml"/> //实体类在hibernate内的映射配置
     <mapping resource="entity/Students.hbm.xml"/>
      <mapping resource="entity/Teachers.hbm.xml"/>
     
 </session-factory>


</hibernate-configuration>

原创粉丝点击