标签:
1.导入19个jar包http://pan.baidu.com/s/1sjlxsbb
2.部署两个xml
hibernate.cfg.xml
<?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> <!-- 数据库url --> <property name="hibernate.connection.url"> jdbc:oracle:thin:@localhost:1521:yanghl </property> <!-- 用户名 --> <property name="hibernate.connection.username">scott</property> <!-- 密码 --> <property name="hibernate.connection.password">tiger</property> <!-- 驱动 --> <property name="hibernate.connection.driver_class"> oracle.jdbc.driver.OracleDriver </property> <!-- 自动更新数据库内容(创建表和约束) --> <property name="hibernate.hbm2ddl.auto">update</property> <!-- 在控制台显示sql语句 --> <property name="hibernate.show_sql">true</property> <!-- sql语句进行格式化 --> <property name="hibernate.format_sql">true</property> <!-- 把需要用到hibernate的持久类xml配置进来 --> <mapping resource="com/bdqn/entity/User.hbm.xml" /> <mapping resource="com/bdqn/entity/Street.hbm.xml" /> <mapping resource="com/bdqn/entity/District.hbm.xml" /> </session-factory> </hibernate-configuration>User.hbm.xml
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="com.bdqn.entity.User" table="pb_users" schema="scott"> <id name="id" type="java.lang.Long"> <column name="id" /> <generator class="sequence"> <param name="sequence">seq_users</param> </generator> </id> <property name="name" type="java.lang.String"> <column name="name" length="20" not-null="true" /> </property> <property name="password" type="java.lang.String"> <column name="password" length="20" not-null="true" /> </property> <property name="image" type="blob" column="image" /> <property name="description" type="clob" column="description" /> <set name="pis" table="PB_PICS" lazy="true"> <key column="USERID"></key> <element column="picpath" type="string" not-null="true" /> </set> <list name="phones" table="news_phones" lazy="true"> <key column="U_ID"></key> <list-index column="POSITION"></list-index> <element column="PHONES" type="string" not-null="true" /> </list> <map name="books" table="PB_BOOKS" lazy="true"> <key column="USERID"></key> <map-key column="GRADID" type="string" ></map-key> <element column="BOOKS" type="string" not-null="true" /> </map> </class> </hibernate-mapping>
1.Hibernate小试牛刀 Hibernate项目环境搭建、Hibernate项目开发示例
标签:
原文地址:http://blog.csdn.net/sgyhl18/article/details/45127999