开发者

property formula not returning the result

I have a table Submission, which has a many to one mapping to a SubmissionType, which has a one to many mapping to SubmissionTypeYear table. Even though this is a one-to-many mapping, there will always be just one SubmissionTypeYear for a SubmissionType. (Don't ask me why the database was designed like this. I wasn't involved and I just have to make it work.)

Therefore, a submission will have a SubmissionType will have a SubmissionTypeYear.

My problem is that in my Submission.hbm.xml, I want a calculated property, which gets me a column value from SubmissionTypeYear. But I don't know what's wrong, it comes back with a zero, when I know that there is a value in the table.

This is my code:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Business.Domain" assembly="Business.Domain">
  <class name="Business.Domain.Submission, Business.Domain" table="dbo.Submission" lazy="true" optimistic-lock="version"  >
    <id name="Id" column="SubmissionId">
      <generator class="identity"/>
    </id>
    <discriminator column ="SubmissionTypeCode"></discriminator>

    <many-to-one name="SubmissionTypeMember"  insert="false" column="SubmissionTypeCode"    class="RefSubmissionType" access ="field.camelcase-underscore" cascade ="none" />

    <property name="Year" formula="(SELECT TOP 1 SubmissionTypeYear.Year FROM SubmissionTypeYear WHERE开发者_开发问答  SubmissionTypeYear.SubmissionTypeCode =  SubmissionTypeCode)" access="field.camelcase-underscore"></property>


</hibernate-mapping>

I thought that it wasn't picking up the SubmissionTypeCode correctly, so I tried with a static string as well, but doesn't seem to be working.

What am I doing wrong? Please help.

Thanks


OK, I figured it out. The problem was with the new Submission types created. As it was a new object and not yet stored in the database, it wasn't able to pick up the calculated field. It was working for all the existing objects. Fixed :)

Hope this helps someone else.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜