MySQL5.0.15
一个问题表(question),一个回答表(answer)分别如下:
create table question
(
qid int auto_increment not null,
title VARCHAR(50),
content text,
itemid int,
subid int,
userid VARCHAR(50),
grade VARCHAR(50),
offerscore int,
status int,
questiontime datetime,
clickcount int,
acceptflag int,
commenflag int,
primary key (qid)
);
create table answer
(
aid int auto_increment not null,
quesans VARCHAR(50),
userid VARCHAR(50),
grade VARCHAR(50),
anstime datetime,
status int,
qid int,
primary key (aid) ,
foreign key (qid) references question(qid) on delete cascade
);question表对应地hibernate3.1的映射文件为:Question.hbm.xml,内容如下:
<hibernate-mapping>
<class name="com.iwtxokhtd.vo.Question" table="question">
<id name="qid" type="java.lang.Integer">
<column name="qid" />
<generator class="native" />
</id>
<property name="title" type="java.lang.String">
<column name="title" length="50" />
</property>
<property name="content" type="java.lang.String">
<column name="content" length="65535" />
</property>
<property name="itemid" type="java.lang.Integer">
<column name="itemid" />
</property>
<property name="subid" type="java.lang.Integer">
<column name="subid" />
</property>
<property name="userid" type="java.lang.String">
<column name="userid" length="50" />
</property>
<property name="grade" type="java.lang.String">
<column name="grade" length="50" />
</property>
<property name="offerscore" type="java.lang.Integer">
<column name="offerscore" />
</property>
<property name="status" type="java.lang.Integer">
<column name="status" />
</property>
<property name="questiontime" type="java.util.Date">
<column name="questiontime" length="19" />
</property>
<property name="clickcount" type="java.lang.Integer">
<column name="clickcount" />
</property>
<property name="acceptflag" type="java.lang.Integer">
<column name="acceptflag" />
</property>
<property name="commenflag" type="java.lang.Integer">
<column name="commenflag" />
</property>
<set name="answers" inverse="true" table="answer">
<key>
<column name="qid" />
</key>
<one-to-many class="org.lxh.myzngt.vo.Answer" />
</set>
</class>
</hibernate-mapping>
answer表对应地hibernate3.1的映射文件为:Answer.hbm.xml,内容如下:
<hibernate-mapping>
<class name="com.iwtxokhtd.vo.Answer" table="answer">
<id name="aid" type="java.lang.Integer">
<column name="aid" />
<generator class="native" />
</id>
<many-to-one name="question" class="org.lxh.myzngt.vo.Question"
fetch="select">
<column name="qid" />
</many-to-one>
<property name="quesans" type="java.lang.String">
<column name="quesans" length="50" />
</property>
<property name="userid" type="java.lang.String">
<column name="userid" length="50" />
</property>
<property name="grade" type="java.lang.String">
<column name="grade" length="50" />
</property>
<property name="anstime" type="java.util.Date">
<column name="anstime" length="19" />
</property>
<property name="status" type="java.lang.Integer">
<column name="status" />
</property>
</class>
</hibernate-mapping>
一个问题表(question),一个回答表(answer)分别如下:
create table question
(
qid int auto_increment not null,
title VARCHAR(50),
content text,
itemid int,
subid int,
userid VARCHAR(50),
grade VARCHAR(50),
offerscore int,
status int,
questiontime datetime,
clickcount int,
acceptflag int,
commenflag int,
primary key (qid)
);
create table answer
(
aid int auto_increment not null,
quesans VARCHAR(50),
userid VARCHAR(50),
grade VARCHAR(50),
anstime datetime,
status int,
qid int,
primary key (aid) ,
foreign key (qid) references question(qid) on delete cascade
);question表对应地hibernate3.1的映射文件为:Question.hbm.xml,内容如下:
<hibernate-mapping>
<class name="com.iwtxokhtd.vo.Question" table="question">
<id name="qid" type="java.lang.Integer">
<column name="qid" />
<generator class="native" />
</id>
<property name="title" type="java.lang.String">
<column name="title" length="50" />
</property>
<property name="content" type="java.lang.String">
<column name="content" length="65535" />
</property>
<property name="itemid" type="java.lang.Integer">
<column name="itemid" />
</property>
<property name="subid" type="java.lang.Integer">
<column name="subid" />
</property>
<property name="userid" type="java.lang.String">
<column name="userid" length="50" />
</property>
<property name="grade" type="java.lang.String">
<column name="grade" length="50" />
</property>
<property name="offerscore" type="java.lang.Integer">
<column name="offerscore" />
</property>
<property name="status" type="java.lang.Integer">
<column name="status" />
</property>
<property name="questiontime" type="java.util.Date">
<column name="questiontime" length="19" />
</property>
<property name="clickcount" type="java.lang.Integer">
<column name="clickcount" />
</property>
<property name="acceptflag" type="java.lang.Integer">
<column name="acceptflag" />
</property>
<property name="commenflag" type="java.lang.Integer">
<column name="commenflag" />
</property>
<set name="answers" inverse="true" table="answer">
<key>
<column name="qid" />
</key>
<one-to-many class="org.lxh.myzngt.vo.Answer" />
</set>
</class>
</hibernate-mapping>
answer表对应地hibernate3.1的映射文件为:Answer.hbm.xml,内容如下:
<hibernate-mapping>
<class name="com.iwtxokhtd.vo.Answer" table="answer">
<id name="aid" type="java.lang.Integer">
<column name="aid" />
<generator class="native" />
</id>
<many-to-one name="question" class="org.lxh.myzngt.vo.Question"
fetch="select">
<column name="qid" />
</many-to-one>
<property name="quesans" type="java.lang.String">
<column name="quesans" length="50" />
</property>
<property name="userid" type="java.lang.String">
<column name="userid" length="50" />
</property>
<property name="grade" type="java.lang.String">
<column name="grade" length="50" />
</property>
<property name="anstime" type="java.util.Date">
<column name="anstime" length="19" />
</property>
<property name="status" type="java.lang.Integer">
<column name="status" />
</property>
</class>
</hibernate-mapping>
解决方案 »
- ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: N
- mysql 还需要优化??
- mysql and or ?
- **********简单到无敌的问题,Apache虚拟主机.***********
- 大家用什么数据抽取工具?
- MySql ADO.NET连接 gbk不支持如何处理?
- sql文的转型!!
- [讨论]oracle和mysql安全性问题(回复有分)
- 两个表 left join查询 条件模糊 请教这条SQL语句哪里不对 应该怎么写
- 求助 SQL 语句
- 关于MYSQL锁定与并发处理
- 像主表和子表中同时插入记录如何写insert语句
[/align]
这是查询问题数量的HQL语句:String hql="select count(q.qid) from Question as q WHERE q.qid IN (SELECT a.qid FROM Answer AS a WHERE a.userid=?)";
这是查询已被采纳的问题数量的HQL语句:String hql="select count(q.qid) from Question as q WHERE q.qid IN (SELECT a.qid FROM Answer AS a WHERE a.userid=? AND status=?)";
这是列出已被采纳的问题列表的HQL语句:String hql="from Question as q WHERE q.qid IN (SELECT a.qid FROM Answer AS a WHERE a.userid=? AND status=?)";
这是列出已回答了的问题列表的HQL语句:String hql="from Question as q WHERE q.qid IN (SELECT a.qid FROM Answer AS a WHERE a.userid=?)";
如果在保持Question.hbm.xml和Answer.hbm.xml文件不变的情况下,使用查询已回答的问题以及已被采纳的问题时就会出现can't resolve property 'qid' in上面的HQL语句异常。
如果在Answer.hbm.xml后面加上: <property name="qid" type="java.lang.Integer">
<column name="qid" />
</property> 并把改成<many-to-one name="question" class="com.iwtxokhtd.vo.Question"
fetch="select"> <many-to-one name="question" class="com.iwtxokhtd.vo.Question"
insert="false" update="false">时, 查询已回答的问题以及已被采纳的问题可以正常使用,但这时回答问题却不成功,就会出现开始给的异常。