我有一个hibernate类question 和answer
建立好双向多对一以后
代码片段如下:question:
<set name="ballotAnswer" cascade="all">
         <key column="b_q_id"></key>
         <one-to-many class="hibernate.BallotAnswer"/>
        </set>
answer:
<many-to-one name="ballotQuestion" column="b_q_id" class="hibernate.BallotQuestion" lazy="false" fetch="select" ></many-to-one>
做查询的代码如下:
int id = new Integer(request.getParameter("id"));
AbstractView av = new AbstractView();
Iterator it = av.getSelectItem("from BallotAnswer where BAId="+id).iterator();
BallotAnswer ba= (BallotAnswer)it.next();
int count = ba.getBACount();
count = count+1;
ba.setBACount(count);
BallotQuestion bq = ba.getBallotQuestion();
System.out.println(bq.getBQAuthor());
BallotAnswer里的值我可以取道,但是BallotQuestion里的值报空

解决方案 »

  1.   

    你检查一下数据库连接,getSelectItem()返回值没有问题吗?!
      

  2.   

    Iterator it = av.getSelectItem("from BallotAnswer where BAId="+id).iterator(); 
    确认下是否查到数据了??
      

  3.   

    <set name="ballotAnswer" cascade="all" inverse="true"
            <key column="b_q_id"> </key> 
            <one-to-many class="hibernate.BallotAnswer"/> 
            </set> 你没设置给它 那里来的值