hibernate 单项多对一 查询问题
查询语句
public static void loadStudent() { Session session = HibernateSessionFactory.openSession(); Student s1 = (Student) session.load(Student.class, 1); //已重写tostring System.out.println(s1); //System.out.println(s1.getClassTable()); }
xml配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="true" package="com.hellojava.entity">
<class name="Student" table="student">
<id name="stuId" column="stuId" type="integer">
<generator class="increment"></generator>
</id>
<property name="stuName" column="stuName" type="string" length="20"></property>
<property name="stuSex" column="stuSex" type="character" length="6"></property>
<property name="stuAge" column="stuAge" type="integer"></property>
<!-- 必须加上此才能查询出外键列insert="true" update="true" -->
<!--
<property name="cid" column="cid" type="integer" insert="true" update="true"></property> -->
<many-to-one name="classTable" class="ClassTable" column="cid"></many-to-one>
</class>
</hibernate-mapping>
求解?