Offhand, setting the "optional" property on the join *may* work for you-not positive about that though.
However, I think in this case you should consider an alternative approach and instead the portion that comes from the view a separate entity. Join is really intended for legacy cases where a single entity (always a 1-1 relationship between the rows in both tables, both halves live and die together as if they were halves of same row, in one table) is, through a legacy mapping choice, mapped across two tables. In this case, since it seems like the "vwGPAPointsAwarded" piece in your secondary table and the piece in your main table do not necessarily live and die together (this piece in the view comes from somewhere later on, maybe, so it's got a different life, at least for the beginning) it seems like it has an at least slightly different life from your main entity, and therefore may be a different conceptual entity... NHibernate can do some tweaking to adjust things when it maps from db to classes, but if the model inherent in your process doesn't fit with what you plan to do mapping-wise, NHibernate's going to have a tough time compensating. Good luck! On Fri, Jan 8, 2010 at 9:16 AM, Jason Dentler <[email protected]>wrote: > 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]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > >--
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.
