配置如下:<?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.ibokee.weibo.bean">
<class name="UserTopic" table="ibokee_wb_usertopic" dynamic-insert="true" dynamic-update="true" >

<id name="id" column="ID" length="11">
<generator class="native" />
</id>
<property name="type" column="type" />
<many-to-one name="user" column="userID"  fetch="select"/>
<many-to-one name="topic" column="topicID"/>
<property name="createTime" column="createTime" type="timestamp" />
</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.ibokee.weibo.bean">
<class name="Topic" table="ibokee_wb_topic" dynamic-insert="true"  dynamic-update="true">

<id name="id" column="ID" length="11">
<generator class="native" />
</id>

<property name="name" column="name" length="20" />
<property name="userCount" column="userCount" length="11"/>
<property name="postCount" column="postCount" length="11"/>
<property name="isRecommend" column="isRecommend" length="11"/>
<property name="isHot" column="isHot" length="11"/>
<property name="desc" column="desc"/>
<property name="picUrl" column="picUrl"/>
<property name="isLock" column="isLock" length="11"/>
<property name="createTime" column="createTime" type="timestamp" />
<many-to-one class="TopicGroup" name="topicGroup" column="groupID"/>
</class>
</hibernate-mapping>
查询用户关注的话题,1-n个查询,而不是一个连接查询,怎么优化成一条连接查询,一条语句!
打印出的sql:
Hibernate: select usertopic0_.ID as ID83_, usertopic0_.type as type83_, usertopic0_.userID as userID83_, usertopic0_.topicID as topicID83_, usertopic0_.createTime as createTime83_ from ibokee_wb_usertopic usertopic0_ where usertopic0_.userID=? and usertopic0_.type=0 order by usertopic0_.createTime desc
Hibernate: select topic0_.ID as ID75_0_, topic0_.name as name75_0_, topic0_.userCount as userCount75_0_, topic0_.postCount as postCount75_0_, topic0_.isRecommend as isRecomm5_75_0_, topic0_.isHot as isHot75_0_, topic0_.desc as desc75_0_, topic0_.picUrl as picUrl75_0_, topic0_.isLock as isLock75_0_, topic0_.createTime as createTime75_0_, topic0_.groupID as groupID75_0_ from ibokee_wb_topic topic0_ where topic0_.ID=?
Hibernate: select topic0_.ID as ID75_0_, topic0_.name as name75_0_, topic0_.userCount as userCount75_0_, topic0_.postCount as postCount75_0_, topic0_.isRecommend as isRecomm5_75_0_, topic0_.isHot as isHot75_0_, topic0_.desc as desc75_0_, topic0_.picUrl as picUrl75_0_, topic0_.isLock as isLock75_0_, topic0_.createTime as createTime75_0_, topic0_.groupID as groupID75_0_ from ibokee_wb_topic topic0_ where topic0_.ID=?
Hibernate: select topic0_.ID as ID75_0_, topic0_.name as name75_0_, topic0_.userCount as userCount75_0_, topic0_.postCount as postCount75_0_, topic0_.isRecommend as isRecomm5_75_0_, topic0_.isHot as isHot75_0_, topic0_.desc as desc75_0_, topic0_.picUrl as picUrl75_0_, topic0_.isLock as isLock75_0_, topic0_.createTime as createTime75_0_, topic0_.groupID as groupID75_0_ from ibokee_wb_topic topic0_ where topic0_.ID=?
Hibernate: select topic0_.ID as ID75_0_, topic0_.name as name75_0_, topic0_.userCount as userCount75_0_, topic0_.postCount as postCount75_0_, topic0_.isRecommend as isRecomm5_75_0_, topic0_.isHot as isHot75_0_, topic0_.desc as desc75_0_, topic0_.picUrl as picUrl75_0_, topic0_.isLock as isLock75_0_, topic0_.createTime as createTime75_0_, topic0_.groupID as groupID75_0_ from ibokee_wb_topic topic0_ where topic0_.ID=?
Hibernate: select topic0_.ID as ID75_0_, topic0_.name as name75_0_, topic0_.userCount as userCount75_0_, topic0_.postCount as postCount75_0_, topic0_.isRecommend as isRecomm5_75_0_, topic0_.isHot as isHot75_0_, topic0_.desc as desc75_0_, topic0_.picUrl as picUrl75_0_, topic0_.isLock as isLock75_0_, topic0_.createTime as createTime75_0_, topic0_.groupID as groupID75_0_ from ibokee_wb_topic topic0_ where topic0_.ID=?
Hibernate: select topic0_.ID as ID75_0_, topic0_.name as name75_0_, topic0_.userCount as userCount75_0_, topic0_.postCount as postCount75_0_, topic0_.isRecommend as isRecomm5_75_0_, topic0_.isHot as isHot75_0_, topic0_.desc as desc75_0_, topic0_.picUrl as picUrl75_0_, topic0_.isLock as isLock75_0_, topic0_.createTime as createTime75_0_, topic0_.groupID as groupID75_0_ from ibokee_wb_topic topic0_ where topic0_.ID=?
Hibernate: select topic0_.ID as ID75_0_, topic0_.name as name75_0_, topic0_.userCount as userCount75_0_, topic0_.postCount as postCount75_0_, topic0_.isRecommend as isRecomm5_75_0_, topic0_.isHot as isHot75_0_, topic0_.desc as desc75_0_, topic0_.picUrl as picUrl75_0_, topic0_.isLock as isLock75_0_, topic0_.createTime as createTime75_0_, topic0_.groupID as groupID75_0_ from ibokee_wb_topic topic0_ where topic0_.ID=?
Hibernate: select topic0_.ID as ID75_0_, topic0_.name as name75_0_, topic0_.userCount as userCount75_0_, topic0_.postCount as postCount75_0_, topic0_.isRecommend as isRecomm5_75_0_, topic0_.isHot as isHot75_0_, topic0_.desc as desc75_0_, topic0_.picUrl as picUrl75_0_, topic0_.isLock as isLock75_0_, topic0_.createTime as createTime75_0_, topic0_.groupID as groupID75_0_ from ibokee_wb_topic topic0_ where topic0_.ID=?
Hibernate: select topic0_.ID as ID75_0_, topic0_.name as name75_0_, topic0_.userCount as userCount75_0_, topic0_.postCount as postCount75_0_, topic0_.isRecommend as isRecomm5_75_0_, topic0_.isHot as isHot75_0_, topic0_.desc as desc75_0_, topic0_.picUrl as picUrl75_0_, topic0_.isLock as isLock75_0_, topic0_.createTime as createTime75_0_, topic0_.groupID as groupID75_0_ from ibokee_wb_topic topic0_ where topic0_.ID=?
Hibernate: select topic0_.ID as ID75_0_, topic0_.name as name75_0_, topic0_.userCount as userCount75_0_, topic0_.postCount as postCount75_0_, topic0_.isRecommend as isRecomm5_75_0_, topic0_.isHot as isHot75_0_, topic0_.desc as desc75_0_, topic0_.picUrl as picUrl75_0_, topic0_.isLock as isLock75_0_, topic0_.createTime as createTime75_0_, topic0_.groupID as groupID75_0_ from ibokee_wb_topic topic0_ where topic0_.ID=?