我的LevelTerm.hbm.xml
文件是:
<hibernate-mapping>
<class name="com.entity.LevelTerm" table="level_term" catalog="test">
<id name="levelId" type="java.lang.Integer">
<column name="level_id" />
<generator class="identity" />
</id>
<property name="level" type="int">
<column name="level" not-null="true" />
</property>
<property name="term" type="int">
<column name="term" not-null="true" />
</property>
<property name="session" type="int">
<column name="session" not-null="true" />
</property>
<list name="list_course">
<key column="level_id"/>
<one-to-many column="course_code" class="com.entity.Course"/>
</list>
</class>
</hibernate-mapping>
我的LevelTerm
课是:
@Entity
public class LevelTerm implements java.io.Serializable {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private Integer levelId;
private int level;
private int term;
private int session;
@OneToMany
private List<Course>list_course;
public List<Course> getList_course() {
return list_course;
}
public void setList_course(List<Course> list_course) {
this.list_course = list_course;
}
public List<Student> getList_student() {
return list_student;
}
public void setList_student(List<Student> list_student) {
this.list_student = list_student;
}
public LevelTerm() {
}
public LevelTerm(int level, int term, int session) {
this.level = level;
this.term = term;
this.session = session;
}
public Integer getLevelId() {
return this.levelId;
}
public void setLevelId(Integer levelId) {
this.levelId = levelId;
}
public int getLevel() {
return this.level;
}
public void setLevel(int level) {
this.level = level;
}
public int getTerm() {
return this.term;
}
public void setTerm(int term) {
this.term = term;
}
public int getSession() {
return this.session;
}
public void setSession(int session) {
this.session = session;
}
}
和hibernate.cfg.xml
配置文件是:
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.current_session_context_class">thread </property>
<property name="hibernate.hbm2ddl.auto">create</property>
<mapping resource="com.entity/Student.hbm.xml"/>
<mapping resource="com/entity/Address.hbm.xml"/>
<mapping resource="com.entity/Course.hbm.xml"/>
<mapping resource="com.entity/LevelTerm.hbm.xml"/>
</session-factory>
</hibernate-configuration>
我的代码应该在 MySQL 数据库中创建一个连接表“LEVEL_TERM_LIST_COURSE”。但是没有创建表。