在做论坛时,我现在遇到一个问题,有两个实体类User和Note,他们是关联关系我在User.hbm.xml的set中设置了lazy属性为“true”表示查询User时,延迟查询Note,在运行时没有问题,但现在,我有一个需求,根据论坛题目查询所有相关的帖子,这时在运行时总是要查询User,但我不想查User,这和User一点关系都没有!请问我应如何解决这个问题。
--------------------------------User.hbm.xml------------------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="luntan.User" table="USER">
<id name="id" column="ID" type="long">
<generator class="increment"/>
</id>
<property name="name" column="NAME" type="string" not-null="true"/>
<property name="password" column="PASSWORD" type="string" not-null="true"/>
<property name="headimage" column="HEADIMG" type="string" not-null="true"/>
<property name="istz" column="ISTZ" type="int" not-null="true"/>
<set
name="note"
cascade="all-delete-orphan"
inverse="true"
lazy="true"
>
<key column="WRITERID"/>
<one-to-many class="luntan.Note"/>
</set>
<!--
<set
name="privateinfo"
inverse="true"
lazy="true"
>
<key column="ORIGID"/>
<one-to-many class="luntan.Privateinfo"/>
</set>
-->
</class>
</hibernate-mapping>
---------------------------------Note.hbm.xml-----------------------------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="luntan.Note" table="NOTE">
<id name="id" column="ID" type="long">
<generator class="increment"/>
</id>
<property name="typeid" column="TYPEID" type="long" not-null="true"/>
<property name="title" column="TITLE" type="string" not-null="true"/>
<property name="content" column="CONTENT" type="string" not-null="true"/>
<property name="publishdate" column="PUBLISHDATE" type="date" not-null="true"/>
<many-to-one
name="people"
column="WRITERID"
class="luntan.People"
not-null="true"/>
<!--
<set
name="fabiaonote"
cascade="all-delete-orphan"
inverse="true"
>
<key column="ORIGID"/>
<one-to-many class="luntan.Answernote"/>
</set>
-->
</class>
</hibernate-mapping>
你只要不是通过关联来取出User对象延迟加载对它没有影响