QQ:5654880

Hibernate初级例子

Hibernate初级

在Myeclipse部署

 

 

实体类:

 

package com.entity;

 

/**

* Teacher entity. @author MyEclipse Persistence Tools

*/

 

public class Teacher implements java.io.Serializable {

 

// Fields

 

private int tids;

private String tname;

private Double tprice;

 

// Constructors

 

/** default constructor */

public Teacher() {

}

 

 

public Teacher(String tname, Double tprice) {

super();

this.tname = tname;

this.tprice = tprice;

}

 

 

public Teacher(int tids, String tname) {

super();

this.tids = tids;

this.tname = tname;

}

public Teacher(int tids, String tname, Double tprice) {

super();

this.tids = tids;

this.tname = tname;

this.tprice = tprice;

}

 

// Property accessors

 

public int getTids() {

return this.tids;

}

 

public void setTids(int tids) {

this.tids = tids;

}

 

public String getTname() {

return this.tname;

}

 

public void setTname(String tname) {

this.tname = tname;

}

 

public Double getTprice() {

return this.tprice;

}

 

public void setTprice(Double tprice) {

this.tprice = tprice;

}

 

}

 

Teacher.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">

<!--

Mapping file autogenerated by MyEclipse Persistence Tools

-->

<hibernate-mapping>

<class name="com.entity.Teacher" table="TEACHER" schema="DSX">

<id name="tids" type="java.lang.Integer">

<column name="TIDS" precision="22" scale="0" />

<generator class="sequence">

<param name="sequence">seq_teacher_tids</param>

</generator>

</id>

<property name="tname" type="java.lang.String">

<column name="TNAME" length="200" />

</property>

<property name="tprice" type="java.lang.Double">

<column name="TPRICE" precision="6" />

</property>

</class>

</hibernate-mapping>

 

 

 

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">

<!-- Generated by MyEclipse Hibernate Tools. -->

<hibernate-configuration>

 

<session-factory>

<property name="dialect">

org.hibernate.dialect.Oracle9Dialect

</property>

<property name="connection.url">

jdbc:oracle:thin:@localhost:1521:orcl

</property>

<property name="connection.username">dsx</property>

<property name="connection.password">admin</property>

<property name="connection.driver_class">

oracle.jdbc.OracleDriver

</property>

<property name="myeclipse.connection.profile">mydb</property>

<property name="show_sql">true</property>

<property name="format_sql">true</property>

<mapping resource="com/entity/Teacher.hbm.xml" />

<mapping resource="com/entity/District.hbm.xml" />

<mapping resource="com/entity/Street.hbm.xml" />

 

</session-factory>

 

</hibernate-configuration>

posted @ 2017-09-11 22:46  大师兄丶2K  阅读(100)  评论(0编辑  收藏  举报