文档详情

Hibernate基础使用教程.doc

发布:2017-04-19约9.66千字共8页下载文档
文本预览下载声明
Hibernate HelloWorld 1、Hibernate简介 历史,和JPA的先后时间、Annotation的提出。 2、环境准备 下载hibernate,如果是3.5以的话,就不需要单独下载Annotation了,否则的话需要单独下载与hibernate版本相对应的Annotation版本。 此次实验使用的是hibernate-release-4.2.2.Final(里面包括Annotation); slf4j版本:slf4j-1.6.1 下载slf4j,对应于hibernate中slf4j api的版本号。 3、第一个Hibernate程序(XML版本)——HelloWorld 步骤如下: 建立新的Java项目,名为:hibernate_0100_HelloWorld; 学习建立User-library-hibernate,并加入相应的jar包; 项目右键→ build path→ configure build path→ add library; 选择User-library,在其中新建library,名为为hibernate; 在该library中加入hibernate所需jar包。 hibernate-release-4.2.2.Final/bin/required/中所以的包; hibernate-release-4.2.2.Final/lib/optional/ehcache/下的:slf4j-api-1.6.1.jar slf4j-1.6.1目录下的:slf4j-nop-1.6.1.jar 引入Oracle的JDBC驱动包; 在Oracle中建立对应的数据库表 create table student(id int primary key,name varchar2(20),age int); create table teacher(id int primary key,name varchar2(20),title varchar2(10));建立hibernate配置文件hibernate.cfg.xml(默认名称,建议不要改) ?xml version=1.0 encoding=utf-8? !DOCTYPE hibernate-configuration PUBLIC -//Hibernate/Hibernate Configuration DTD 3.0//EN /dtd/hibernate-configuration-3.0.dtd hibernate-configuration session-factory !-- Database connection settings -- property name=connection.driver_classoracle.jdbc.driver.OracleDriver/property property name=connection.urljdbc:oracl:thin:@05:1521:daocn/property property name=connection.usernamescott/property property name=connection.passwordtiger/property !-- 连接池,暂时不需要 -- !-- JDBC connection pool (use the built-in) -- !-- property name=connection.pool_size1/property -- !-- SQL dialect -- property name=dialectorg.hibernate.dialect.OracleDialect/property !-- Enable Hibernates automatic session context management -- !-- property name=current_session_context_classthread/property -- !-- 关闭二级缓存 -- !-- Disable the second-level cache -- property name=vider_classernal.NoCacheProvider/property !-- 回显hibernate生成的SQL语句 -- !-- Echo all executed SQL to stdout -- property name=show_sqltrue/property !-- Drop and re-create the data
显示全部
相似文档