1. 全貌图
hibernate_1.jpg
2. hibernate_2.jpg
hibernate.cfg.xml
hibernate.cfg.xml文件详细内容:
ho.hbm.xml文件详细内容:
3.hibernate.cfg.xml文件详细内容:
<textarea name="code" class="xhtml" rows="15" cols="50"><?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"> <!-- Generated by MyEclipse Hibernate Tools. --> <hibernate-configuration> <session-factory> <property name="connection.username">jlsys</property> <property name="connection.url"> jdbc:oracle:thin:@192.168.5.157:1521:jlcctest </property> <property name="dialect"> org.hibernate.dialect.Oracle9Dialect </property> <property name="myeclipse.connection.profile"> jlcctest </property> <property name="connection.password">jlsys</property> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </property> <mapping resource="com/zz/Ho.hbm.xml" /> </session-factory> </hibernate-configuration></textarea>
4.hibernate.reveng.xml文件详细内容:
<textarea name="code" class="xhtml" rows="15" cols="50"><?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" > <hibernate-reverse-engineering> </hibernate-reverse-engineering></textarea>
5.ho.hbm.xml文件详细内容:
<textarea name="code" class="xhtml" rows="15" cols="50"><?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"> <!-- Mapping file autogenerated by MyEclipse Persistence Tools --> <hibernate-mapping> <class name="com.zz.Ho" table="HO" schema="IEP"> <composite-id name="id" class="com.zz.HoId"> <key-property name="id" type="java.lang.String"> <column name="ID" length="10" /> </key-property> <key-property name="username" type="java.lang.String"> <column name="USERNAME" length="10" /> </key-property> </composite-id> </class> </hibernate-mapping> </textarea>
6. 执行代码的测试类:
<textarea name="code" class="java" rows="15" cols="50">package com.zz; import org.hibernate.Session; import org.hibernate.Transaction; public class test_ho { public static void main(String[] args) { // TODO Auto-generated method stub HoId ho_1 = new HoId("002","cyj"); Ho test = new Ho(); test.setId(ho_1); System.out.print(test.getId()); //--以上为生成对象 //--下面为提交到数据库 HoDAO hdao = new HoDAO(); Session s=hdao.getSession(); //获得session对象 //必须要提交事务,否则数据插不到数据库里 Transaction tran = s.beginTransaction(); s.save(test); tran.commit(); } } </textarea>