首页 > 学院 > 开发设计 > 正文

Hibernate笔记

2019-11-08 18:39:22
字体:
来源:转载
供稿:网友

Hibernate简介:

用面向对象的思想去管理数据库,如果程序中都是sql语句,则难以维护。

其他主流的ORM框架技术:Mybatis

hibernate需要配置的jar包:hibernate-core,MySQL-jdbc,junit4

1.建立xml配置文件:hibernate.cfg.xml

    <session-factory>

    <PRoperty name="connection.username">root</property> <!-- 连接数据库的用户名 -->        <property name="connection.passWord">root</property>   <!-- 连接数据库的密码 -->        <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <!--  方言 -->        <property name="connection.url">jdbc:mysql:///hibernate?useUnicode=true&amp;characterEncoding=UTF-8</property> <!--  JDBC地址 -->        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>   <!-- 数据库JDBC的驱动 -->        <property name="myeclipse.connection.profile">MyEclipse Derby</property>        <property name="show_sql">true</property>    <property name="format_sql">true</property>    <property name="hbm2ddl.auto">create</property>    </session-factory>

2.创建实体类:

// 1.共有的类// 2.提供共有的不带参数的默认的构造方法// 3.属性私有// 4.属性setget封装


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表