日期:2014-05-18  浏览次数:20717 次

Hibernate连接查询问题
学生基本信息
<?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" >
<hibernate-mapping package="com.xin.model">
<class name="StudentInfo" table="t_main" lazy="false">    <!-- 类对应一个表 -->
<id name="studentID" column="xh">
<generator class="assigned" /> <!-- 主键的生成策略 -->
</id>
<property name="studentName" column="XM" />
<property name="classID" column="bj" />
<property name="majorName" column="ZYMC" />
<property name="departName" column="FYXB" />
<property name="entime" column="RXNF" />
<one-to-one name="poorstudentinfo" class="com.xin.model.PoorStudentInfo"></one-to-one>
<set name="prizeinfo" lazy="false">
<key column="studentID"></key>
<one-to-many class="PrizeInfo" />
</set>
</class>
</hibernate-mapping>


奖项
<?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" >
<hibernate-mapping package="com.xin.model">
<class name="PrizeInfo" table="jxj_PrizeInfo" lazy="false">    <!-- 类对应一个表 -->
<id name="ID" column="ID">
<generator class="increment" /> <!-- 主键的生成策略 -->
</id>
<property name="prizeOption" />
<property name="schoolYear" />
<many-to-one name="studentinfo" class="StudentInfo" lazy="false" column="studentID"/>
</class>
</hibernate-mapping>



main方法
public static void main(String[] args) {
Session session=HibernateSessionFactory.getSessionFactory().getCurrentSession();
Transaction tx=session.beginTransaction();
String hqlone="select count(*) from PrizeInfo p,StudentInfo s where p.schoolYear='2012-2013' and s.classID like '1130%' and p.prizeOption='一等奖' and p.studentID=s.studentID";
Long i=(Long) session.createQuery(hqlone).uniqueResult();
System.out.println(i);
tx.commit();
}


这么写结果出现
log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" org.hibernate.QueryException: could not resolve property: studentID of: com.xin.model.PrizeInfo [select s from com.xin.model.PrizeInfo p,com.xin.model.StudentInfo s where p.schoolYear='2012-2013' and s.classID like '1130%' and p.prizeOption='一等奖' and p.studentID=s.studentID]
at org.hibernate.persister.entity.AbstractPrope