}
package ctl.annotion.teacher;
import javax.persistence.Column;
import javax.persistence.Entity;//注意是javax.persistence
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Teacher {
private int id;
private String name;
private String title;
@Id//@Id在哪那个字段即为主键
@GeneratedValue(strategy = GenerationType.AUTO) ////在mysql中可以实现从1自增但是在orcale中虽然实现了自增但是不是从1开始行
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
<?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="hbm2ddl.auto">update</property>
<property name="dialect">
org.hibernate.dialect.Oracle9Dialect
</property>
<property name="connection.url">
jdbc:oracle:thin:@localhost:1521:orcl
</property>
<property name="connection.username">scott</property>
<property name="connection.password">Admin518</property>
<property name="connection.driver_class">
oracle.jdbc.driver.OracleDriver
</property>
<property name="myeclipse.connection.profile">
oracle.jdbc.driver.OracleDriver
</property>
<property name="format_sql">true</property>
<property name="show_sql">true</property><mapping resource="ctl/hibernate/db/OrcaleStudent.hbm.xml" />
<mapping class="ctl.annotion.teacher.Teacher"/>
</session-factory>
</hibernate-configuration>