I have a standard Person class with matching Person table. However, there is
a single column (GPA) from a view (vwGPAPointsAwarded) that I am <join>ing.
Since it's a view, I need NHibernate to treat the entire view as read-only,
not just the column. When I persist a new Person, NHibernate fires off an
INSERT for this view, which results in a SQL exception. I suspect the same
would happen for DELETEs, but I never delete people.

As a work-around, I've created an INSTEAD OF INSERT, UPDATE, DELETE trigger
on the view that does nothing, which prevents the SQL exception. I would
rather find a way to make NHibernate understand my intention.

My mapping is similar to the following:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="Nursing.Core.Person, Nursing.Core" table="Person">
    <id name="ID" column="ID" type="Int32" unsaved-value="0">
      <generator class="native" />
    </id>
    <property name="LastName" type="String" length="255" />
    <property name="FirstName" type="String" length="255" />
    <property name="MiddleName" type="String" length="255" />
    <property name="Suffix" type="String" length="255" />
    <property name="BirthDate" type="DateTime" />
    <property name="KeepPrivate" type="Boolean" />
    <property name="Gender" access="property"
type="Nursing.Data.GendersUserType, Nursing.Data">
      <column name="Gender" not-null="false" sql-type="char(1)" />
    </property>
    <bag name="Addresses" lazy="true" inverse="true">
      <key column="ID" />
      <one-to-many class="Nursing.Core.Address, Nursing.Core"/>
    </bag>
    <bag name="EMailAddresses" lazy="true" inverse="true">
      <key column="ID" />
      <one-to-many class="Nursing.Core.EMail, Nursing.Core"/>
    </bag>
    <join table="vwGPAPointsAwarded" optional="true">
      <key column="ID" />
      <property name="GPA" column="GPA" insert="false" update="false"  />
    </join>

  </class>
</hibernate-mapping>

This was my first NHibernate app, so please excuse the worst practices like
the auto number integer identity.
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.

Reply via email to