Well, I tried it after you mentioned it, but I believe it is not even
closely related to my problem, since I'm not deleting anything.


On Oct 5, 2:36 pm, webpaul <[email protected]> wrote:
> Have you tried cascade="none"?
>
> On Oct 4, 3:27 am, Ricardo Peres <[email protected]> wrote:
>
>
>
> > Hello,
>
> > I have an entity containing a query-only property with a where clause
> > (similar to Ayende's example). Whenever I try to list a collection of
> > these entities and I load a collection that refers to them, NHibernate
> > tries to save each of my entities, and causes an exception. My
> > entities are like this:
>
> > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
> > namespace="NHibernateTest" assembly="NHibernateTest" auto-
> > import="true" default-access="property">
> >   <class name="O" table="`O`">
> >     <id name="Id" column="`ID`">
> >       <generator class="identity"/>
> >     </id>
> >     <property name="Date" column="`DATE`"/>
> >     <many-to-one name="M" column="`MID`" fetch="join" outer-
> > join="false" not-null="true"/>
> >   </class>
> > </hibernate-mapping>
>
> > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
> > namespace="NHibernateTest" assembly="NHibernateTest" auto-
> > import="true" default-access="property">
> >   <class name="M" table="`M`">
> >     <id name="Id" column="`MID`">
> >       <generator class="identity"/>
> >     </id>
> >     <set name="RecentO" mutable="false" optimistic-lock="false"
> > access="none" where="(Date >= (GetDate() - 30))">
> >       <key column="`MID`"/>
> >       <one-to-many class="O"/>
> >     </set>
> >     </class>
> > </hibernate-mapping>
>
> > And my classes:
>
> > namespace NHibernateTest
> > {
> >         [Serializable]
> >         public class O
> >         {
> >                 public virtual Int32 Id
> >                 {
> >                         get;
> >                         private set;
> >                 }
>
> >                 public virtual M M
> >                 {
> >                         get;
> >                         set;
> >                 }
>
> >                 public virtual DateTime Date
> >                 {
> >                         get;
> >                         set;
> >                 }
>
> >                 public override Boolean Equals(Object obj)
> >                 {
> >                         if (!(obj is O))
> >                         {
> >                                 return (false);
> >                         }
>
> >                         if (Object.ReferenceEquals(this, obj) == true)
> >                         {
> >                                 return (true);
> >                         }
>
> >                         O other = obj as O;
>
> >                         return (other.Id == this.Id);
> >                 }
> >         }
>
> >         [Serializable]
> >         public class M
> >         {
> >                 public virtual Int32 Id
> >                 {
> >                         get;
> >                         private set;
> >                 }
>
> >                 public virtual IList<O> O
> >                 {
> >                         get;
> >                         private set;
> >                 }
>
> >                 public override Boolean Equals(Object obj)
> >                 {
> >                         if (!(obj is M))
> >                         {
> >                                 return (false);
> >                         }
>
> >                         if (Object.ReferenceEquals(this, obj) == true)
> >                         {
> >                                 return (true);
> >                         }
>
> >                         M other = obj as M;
>
> >                         return (this.Id == other.Id);
> >                 }
> >         }
>
> > }
>
> > Here is the code that causes the exception:
>
> > IList<M> listM = session.CreateCriteria<M>().List<M>();
> > IList<O> listO = session.CreateCriteria<O>().List<O>(); <-- here
>
> > The actual exception is:
>
> > GenericAdoException: "could not delete collection:
> > [NHibernateTest.M.RecentO#2][SQL: UPDATE [O] SET [MID] = null WHERE
> > [MID] = @p0 AND ((Date >= (GetDate() - 30)))]"
> > InnerException: {"Cannot insert the value NULL into column 'MID',
> > table 'NHibernateTest.dbo.O'; column does not allow nulls. UPDATE
> > fails.\r\nThe statement has been terminated."}
>
> > Indeed column MID is NOT NULL, but I don't know why NHibernate is
> > trying to persist my entities, I have explicitly marked the query-only
> > property as mutable="false" and optimistic-lock="false".
>
> > Any clues?
>
> > Thanks,
>
> > Ricardo Peres
--~--~---------~--~----~------------~-------~--~----~
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