开发者

HQL: query only base table from <join> entity

I have this mapping

<class name="Person" table="person">
<id name="Id" column="id" type="Int32" unsaved-value="0">
  <generator class="native" />
</id>

<property name="Code" column="code" type="String" 开发者_开发技巧not-null="true" />
<property name="FirstName" column="firstName" type="String" not-null="true" />
<property name="MiddleName" column="middleName" type="String" not-null="false" />
<property name="LastName" column="lastName" type="String" not-null="false" />

<join table="personPhoto" optional="true">
  <key column="personId" />
  <property name="Photo" column="pictureContent" not-null="false" />
</join>

and the generated SQL always use left outer join, which is correct. However, is it possible to tell HQL to query only from person table, since I'm not always need 'Photo' property? And how?


Is there a one-to-one relationship between person and personPhoto columns?

If you want to load the person's photo lazily, I believe you have to change join mapping to one-to-one mapping and create a new class for personPhoto. This way Hibernate would be able to insert a proxy object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜