有两张表(question、answer),它们存在着一对多关系(question->answer)和多对一关系(answer->question)。
在Answer.java中定义有:
public class Answer {
private String userid;
private Question question;
private int qid;
}
在answer.hbm.xml中有:
<many-to-one name="question" class="org.lxh.myzngt.vo.Question" fetch="select">
<column name="qid" />
</many-to-one>
所以SQL语句如下:
public List queryByUserAnswer(String userid, int currentPage, int lineSize) {
List all = null;
String hql = "from Question as q where q.qid in(select a.question.qid from Answer as a where a.userid=?)";
Query q = super.getSession().createQuery(hql);
q.setString(0, userid);
// 分页操作。
q.setFirstResult((currentPage - 1) * lineSize);
q.setMaxResults(lineSize);
all = q.list();
return all;
}
否则报错:
org.hibernate.QueryException: could not resolve property: qid of: org.lxh.myzngt.vo.Answer [select count(q.qid) from org.lxh.myzngt.vo.Question as q where q.qid in(select a.qid from org.lxh.myzngt.vo.
Answer as a where a.userid=?)]
1.起初没有创建序列s_log,因此需要在Oracle补上s_log序列。
<!-- 增加 日志 -->
<insert id="logSave"
parameterClass="com.reportcenter.sys.dto.OperateLogDto">
INSERT INTO
T_LOG(C_AUTOID,USRCDE,USRADDRESS,OPERATION,BEGINTME,ENDTME,OPERATETIMER,STATE,MESSAGE) VALUES(s_log.nextval,#usrCde#,#usrAddress#,#operation#,#beginTme#,#endTme#,#operateTimer#,#state#,#message#)
</insert>
posted on 2009-03-28 16:46
圣克尔·光 阅读(220)
评论(0) 编辑 收藏