配置hibernate
来源:互联网 发布:金融it行业发展前景 编辑:程序博客网 时间:2024/05/19 08:43
首先在www.hibernate.org里面下载3.6.0final(http://sourceforge.net/projects/hibernate/files/hibernate3/),beta版本可能会不是很稳定。
在MyEclipse里面建一个Java项目--》构建路径--》导入相关包,如下:
1、hibernate-distribution-3.6.0.Final--》hibernate3.jar
2、hibernate-distribution-3.6.0.Final--》lib--》jpa--》hibernate-jpa-2.0-api-1.0.0.Final.jar
3、hibernate-distribution-3.6.0.Final--》lib--》required--》下面的所有包
4、根据3中的一个包,如slf4j-api-1.6.1.jar,下载对应的包slf4j-nop-1.6.1.jar
5、当然还要对应的连接数据库的驱动包
包导入完成之后就开始编写hiberbate的相关配置文件:
1、在src根目录下建立hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/temp9_12</property>
<property name="connection.username">***</property>
<property name="connection.password">***</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<mapping resource="modle/Student.hbm.xml"/>
</session-factory>
</hibernate-configuration>
2、建立一个类
public class Student {
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
3、建立对应的配置文件
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"><hibernate-mapping >
<class name="modle.Student" >
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
</class>
</hibernate-mapping>
4、建立一个测试类
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class StuTest {
public static void main(String args[]){
Configuration cfg = new Configuration().configure();
SchemaExport sExport = new SchemaExport(cfg);
sExport.create(true, true);
}
}
OK准备工作就绪,打开数据库,运行测试文件。
- hibernate-hibernate的配置
- 【Hibernate】2.Hibernate配置
- Hibernate 配置!
- Hibernate配置
- Hibernate配置
- Hibernate 配置
- Hibernate配置
- Hibernate配置
- Hibernate配置
- Hibernate配置
- hibernate 配置
- Hibernate 配置
- Hibernate 配置
- hibernate配置
- 配置HIbernate
- Hibernate 配置
- Hibernate配置
- Hibernate配置
- php邮件发送SMTP
- shell实例浅谈之七检测用户输入串的合法性
- hibernate基础学习
- 啦啦啦啦、新人学习中。。
- JS前台应用
- 配置hibernate
- java发送udp广播包
- div 左中右结构布局问题
- adb shell 查看数据库
- 【求助】如何实现在并肩看中加入代码啊
- JavaScipt——基于对象和事件驱动的客户端语言
- 滚动加载更多
- Android ViewPager使用详解
- Python学习笔记9:标准库之日期时间(time包,datetime包)