hibernate环境搭建
2016-12-29 16:44
246 查看
在经历重重困难,尝试各种方法,终于搭建好了hibernate的开发环境
1、hibernate版本:
不要尝试高版本的hibernate,会出现某些系统依赖库找不到,我用的版本是:hibernate-release-4.2.21.Final,
2、jdk版本:官方要求1.6以上,我用的是jdk1.7.0_79
3、需要加载的jar包
lib/required里面全部
lib\optional\c3p0里面全部
jdbc的jar包(我用的是sql server2005)
4、bean对象:
就是普通的bean文件,带有set和get方法
5、主程序:
News n = new News();
n.setId(5);
n.setMac("1230");
n.setSn("renliansong");
@SuppressWarnings("deprecation")
SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
session.save(n);
session.getTransaction().commit();
6、配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.connection.password">******</property>
<property name="hibernate.connection.url">jdbc:sqlserver://localhost:1433;DatabaseName=suifeng</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.current_session_context_class">thread</property>
<mapping class="org.crazyit.app.domain.News"/>
</session-factory>
</hibernate-configuration>
(注意红色字体部分根据实际修改,连接信息也需要根据数据库进行修改)
1、hibernate版本:
不要尝试高版本的hibernate,会出现某些系统依赖库找不到,我用的版本是:hibernate-release-4.2.21.Final,
2、jdk版本:官方要求1.6以上,我用的是jdk1.7.0_79
3、需要加载的jar包
lib/required里面全部
lib\optional\c3p0里面全部
jdbc的jar包(我用的是sql server2005)
4、bean对象:
就是普通的bean文件,带有set和get方法
5、主程序:
News n = new News();
n.setId(5);
n.setMac("1230");
n.setSn("renliansong");
@SuppressWarnings("deprecation")
SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
session.save(n);
session.getTransaction().commit();
6、配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.connection.password">******</property>
<property name="hibernate.connection.url">jdbc:sqlserver://localhost:1433;DatabaseName=suifeng</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.current_session_context_class">thread</property>
<mapping class="org.crazyit.app.domain.News"/>
</session-factory>
</hibernate-configuration>
(注意红色字体部分根据实际修改,连接信息也需要根据数据库进行修改)
相关文章推荐
- java+mysql+hibernate环境搭建所需的下载地址
- struts+spring+hibernate项目开发环境的搭建——eclipse3.3+MyEclipse6.0+MySql4.1
- 《妙解Hibernate 3.X》读书笔记一-Hibernate概述及环境搭建
- Hibernate环境的搭建
- Hibernate环境搭建
- eclipse+hibernate+structs 环境搭建
- Hibernate基本开发环境搭建
- NetBeans6.1下搭建Struts2.0+Spring2.5+Hibernate3开发环境
- spring-jpa(hibernate实现)环境搭建
- Hibernate环境搭建
- 搭建JDK1.6.0+MyEclipse_6.0.1GA+MySQL5.0+Hibernate测试环境
- 搭建和配置Spring与Hibernate整合的环境
- JSF+Spring+JPA(Hibernate实现)的环境搭建
- 《妙解Hibernate 3.X》读书笔记一-Hibernate概述及环境搭建
- Hibernate3.6 Annotation oracle环境搭建
- spring+hibernate+struts环境搭建
- Hibernate学习手记(1)--搭建环境
- Hibernate3.5.4环境搭建中常见异常的解决办法
- Spring 3.1.0 + Hibernate 3.0 Eclipse IDE 环境的搭建
- Hibernate环境搭建详述(精品)