It is not legacy so I will remove the composite key.

On Wed, Dec 24, 2008 at 11:49 AM, Will Shaver <[email protected]> wrote:

>
> Is this a legacy database you're mapping out? Do you really need to
> use a composite key here? What's the "PropertyId" referencing?
>
> Here's what I think is happening here. You have these entities:
>
> User< -> Favourite < - > Property
>
> You create a Favourite assigning it to both a User and a Property. All is
> fine.
>
> You remove the Favourite from the user, NH attempts to set a Null
> value for the composite key. Null values aren't allowed in keys so it
> freaks out.
>
> You add all-delete-orphan to the mapping.
>
> Removing the favourite from the collection DOES NOT create an orphan
> because it is still referenced by the Property mapping.
>
> Best: Don't use composite ID.
> Might work: Remove the reference to both Property and User before
> attempting to save.
>
>  -Will
>
>
>
> On Tue, Dec 23, 2008 at 4:45 PM, Craig van Nieuwkerk <[email protected]>
> wrote:
> > Here is the favourite mapping.
> > <?xml version="1.0" encoding="utf-8" ?>
> > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
> > namespace="BaseEstate.Model.Entities" schema="BaseEstate"
> > assembly="BaseEstate.Model" default-lazy="false">
> >   <class name="BaseEstate.Model.Entities.Favourite, BaseEstate.Model"
> > table="Favourite" >
> >     <composite-id unsaved-value="any">
> >       <key-property name="PropertyId" column="PropertyId"
> > type="string"></key-property>
> >       <key-property name="UserId" column="UserId"
> type="int"></key-property>
> >     </composite-id>
> >     <property name="Title" column="Title" type="string" />
> >     <property name="Link" column="Link" type="string" />
> >   </class>
> > </hibernate-mapping>
> >
> >
> > On Wed, Dec 24, 2008 at 4:17 AM, Will Shaver <[email protected]>
> wrote:
> >>
> >> Post your mapping for the Favourite class?
> >>
> >> It looks like you probably have a NOT NULL constraint on the foreign
> >> key mapping the Favourite to User. Do other collections reference the
> >> Favourite class? Sometimes all-delete-orphan doesn't work if the
> >> entity is not actually an orphan.
> >>
> >>
> >>  -Will
> >>
> >> On Tue, Dec 23, 2008 at 5:23 AM, Craig van Nieuwkerk <[email protected]
> >
> >> wrote:
> >> > Thanks, but I still get the same error.
> >> >
> >> > On Wed, Dec 24, 2008 at 12:04 AM, Stefan Sedich
> >> > <[email protected]>
> >> > wrote:
> >> >>
> >> >> Try Change cascade on the collection to all-delete-orphan so that the
> >> >> child items are removed on deletion
> >> >>
> >> >> Cheers
> >> >>
> >> >> Stefan Sedich
> >> >>
> >> >>
> >> >> On 23/12/2008, at 9:40 PM, "Craig van Nieuwkerk" <[email protected]>
> >> >> wrote:
> >> >>
> >> >> > I have a Master Detail relationship configured. The hbm file is
> >> >> > below. When I run some code like this
> >> >> >
> >> >> > Favourite favourite = favourites.Find(f => f.Id== id);
> >> >> > user.Favourites.Remove(favourite);
> >> >> > m_UserRepository.Save(ref user);
> >> >> >
> >> >> > I get the error message
> >> >> >
> >> >> > NHibernate.Exceptions.GenericADOException: could not delete
> >> >> > collection rows: [Model.Entities.User.Favourites#249][SQL: SQL not
> >> >> > available] ---> System.Data.SqlClient.SqlException: Cannot insert
> >> >> > the value NULL into column 'UserId', table 'BE.Favourite'; column
> >> >> > does not allow nulls. UPDATE fails.
> >> >> >
> >> >> > Any suggestions on what this means please help.
> >> >> >
> >> >> > Craig.
> >> >> >
> >> >> > <?xml version="1.0" encoding="utf-8" ?>
> >> >> > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
> >> >> > namespace="Model.Entities" schema="BE" assembly="Model" default-
> >> >> > lazy="false">
> >> >> >   <class name="Model.Entities.User, Model" table="Users" >
> >> >> >     <id name="UserId" column="UserId" type="int" unsaved-value="0">
> >> >> >       <generator class="native" />
> >> >> >     </id>
> >> >> >     <property name="UserName" column="UserName" type="string" />
> >> >> >
> >> >> >     <bag name="Favourites" cascade="all" lazy="true">
> >> >> >       <key column="UserId"/>
> >> >> >       <one-to-many class="Model.Entities.Favourite, Model"/>
> >> >> >     </bag>
> >> >> >
> >> >> >   </class>
> >> >> > </hibernate-mapping>
> >> >> >
> >> >> >
> >> >> > >
> >> >>
> >> >>
> >> >
> >> >
> >> > >
> >> >
> >>
> >>
> >
> >
> > >
> >
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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