开发者

NHibernate simple collection of joined-subclass entities

开发者 https://www.devze.com 2023-02-24 08:05 出处:网络
I\'m trying to map a set of joined-subclass entities to a parent entity. The SQL being produced by NHibernate seems to be incorrect. Am I missing anything in my mapping? Is there another way I can app

I'm trying to map a set of joined-subclass entities to a parent entity. The SQL being produced by NHibernate seems to be incorrect. Am I missing anything in my mapping? Is there another way I can approach this problem?

<class name="ResultItem" table="result">

  <id name="ID">
    <generator class="identity" />
  </id>

  <many-to-one name="Job" column="J开发者_运维技巧obID"/>
  <property name="Timestamp"/>
  <many-to-one name="User" column="UserID"/>

  <joined-subclass name="ResultItemAttachment" table="result_attachment">
    <key column="ID"/>
    <property name="Comment"/>
  </joined-subclass>

</class>

This is the SQL being generated by NHibernate. It seems as if its getting confused between super and sub class members? The only table with JobID is the result table and not result_attachment.

SELECT attachment0_.JobID as JobID1_,
       attachment0_.ID as ID1_,
       attachment0_.ID as ID26_0_,
       attachment0_1_.JobID as JobID26_0_,
       attachment0_1_.`Timestamp` as Timestamp26_0_,
       attachment0_1_.UserID as UserID26_0_,
       attachment0_.`Comment` as Comment33_0_
FROM result_attachment attachment0_
inner join result attachment0_1_ on attachment0_.ID=attachment0_1_.ID
WHERE attachment0_1_.JobID=?;

Thanks in advance


I'm afraid this is currently a bug in NHibernate (in there since 2.1 :|) apperently there is a fix in the current alpha of 3.2

https://nhibernate.jira.com/browse/NH-1747

Possible work around is to manually fetch the bag at runtime. Hardly ideal, other option would be to try and get the alpha version running but running an alpha in a production environment is hardly a great idea.

0

精彩评论

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