hibernate持久化数据实例解析

来源:互联网 发布:运动控制卡编程 编辑:程序博客网 时间:2024/06/14 16:29

1. 配置好hibernate对象关系映射(文件名如:类名.hbm.xml)

*配置好与数据库表的属性关系

2. 配置好hibernate配置文件(即是:hibernate.cfg.xml)

需要进行如下配置

<hibernate-configuration>

<session-factory>

*连接数据库的URL:

实例--<property name="connection.url">jdbc:mysql://localhost:3306/testdb</property>

*连接数据库方言

实例--<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<property name="myeclipse.connection.profil">testdb</property>

*密码

<property name="connection.password">11</property>

*驱动程序

<property name="connection,driver_class">com.mysql.jdbc.Driver</property>

*映射文件路径

<mapping resource="com/entity/Department.hbm.xml"</property>

<session-factory>

<hibernate-configuration>

3.测试程序执行顺序

a.得到Configuration实例

Configuration conf = Configuration.configuration();

b.得到SessionFactory的一个实例

SessionFactory sf = conf.buildSessionFactory();

c.得到一个数据库

SessionFactory sf = sf.openSession();


0 0
原创粉丝点击