开发者

HQL: query only base table from <join> entity

开发者 https://www.devze.com 2023-03-06 04:28 出处:网络
I have this mapping <class name=\"Person\" table=\"person\"> <id name=\"Id\" column=\"id\" type=\"Int32\" unsaved-value=\"0\">

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

精彩评论

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