> Just seemed odd to see three sql statements, when only two would be
required.

that is what I responded to. You _can't_ make it only two statements.

On Tue, Oct 21, 2008 at 7:04 PM, Tim Barcz <[EMAIL PROTECTED]> wrote:

> I'm not pointing fingers ... and am satisfied with the solution if that's
> how everyone else is doing it.
>
> Just seemed odd to see three sql statements, when only two would be
> required.
>
> I love NH and most of my troubles are my own ignorance of the best way to
> do this.  If you and others say this is acceptable in NH then I am fine with
> it.
>
> No complaints here.
>
>
> On Tue, Oct 21, 2008 at 12:01 PM, Ayende Rahien <[EMAIL PROTECTED]> wrote:
>
>> Tim,
>> That is a limitation of SQL, not NH.
>>
>>
>> On Tue, Oct 21, 2008 at 6:58 PM, Tim Barcz <[EMAIL PROTECTED]> wrote:
>>
>>> Setttling on the following:
>>>
>>> Unidirectional mapping cannot complete with two statements...must be
>>> three....and have to have a nullable foreign-key field
>>>
>>> On Tue, Oct 21, 2008 at 11:36 AM, Tim Barcz <[EMAIL PROTECTED]> wrote:
>>>
>>>> But then it's bidirectional....I have it bidirectional right now but I
>>>> don't want it bidirectional.
>>>>
>>>>
>>>> On Tue, Oct 21, 2008 at 11:31 AM, Ayende Rahien <[EMAIL PROTECTED]>wrote:
>>>>
>>>>> You don't have the mapping mapped from the WishList side of things.
>>>>> If you would, you would get what you expect.
>>>>>
>>>>>
>>>>> On Tue, Oct 21, 2008 at 6:24 PM, Tim Barcz <[EMAIL PROTECTED]> wrote:
>>>>>
>>>>>> Tried putting the table in the user mapping (see below)...however that
>>>>>> resulted in three calls being made (and I have to have a nullable foreign
>>>>>> key)
>>>>>>
>>>>>> NHibernate: INSERT INTO Users (First, Last) VALUES (@p0, @p1); select
>>>>>> SCOPE_IDENTITY(); @p0 = 'Tim', @p1 = 'Barcz'
>>>>>> NHibernate: INSERT INTO WishLists (Name) VALUES (@p0); select
>>>>>> SCOPE_IDENTITY(); @p0 = 'Sample'
>>>>>> NHibernate: UPDATE WishLists SET UserId = @p0 WHERE WishListId = @p1;
>>>>>> @p0 = '17', @p1 = '9'
>>>>>>
>>>>>> if I put in inverse="true" as Ayende suggest, I get two calls to DB
>>>>>>
>>>>>> NHibernate: INSERT INTO Users (First, Last) VALUES (@p0, @p1); select
>>>>>> SCOPE_IDENTITY(); @p0 = 'Tim', @p1 = 'Barcz'
>>>>>> NHibernate: INSERT INTO WishLists (Name) VALUES (@p0); select
>>>>>> SCOPE_IDENTITY(); @p0 = 'Sample'
>>>>>>
>>>>>> But the data is now corrupted because the UserId was not added to the
>>>>>> WishList
>>>>>>
>>>>>> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
>>>>>> namespace="NHWishList.Model" assembly="NHWishList">
>>>>>>     <class name="User" table="Users">
>>>>>>         <id name="UserId" column="UserId" type="Int32"
>>>>>> unsaved-value="0">
>>>>>>             <generator class="native" />
>>>>>>         </id>
>>>>>>         <property name="First" column="First" length="50"
>>>>>> not-null="true" />
>>>>>>         <property name="Last" column="Last" length="50"
>>>>>> not-null="true" />
>>>>>>
>>>>>>         <bag name="WishLists" cascade="all" table="WishLists">
>>>>>>             <key column="UserId"/>
>>>>>>             <one-to-many class="WishList" />
>>>>>>         </bag>
>>>>>>     </class>
>>>>>> </hibernate-mapping>
>>>>>>
>>>>>> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
>>>>>> namespace="NHWishList.Model" assembly="NHWishList">
>>>>>>     <class name="WishList" table="WishLists">
>>>>>>         <id name="WishListId" column="WishListId" type="Int32"
>>>>>> unsaved-value="0">
>>>>>>             <generator class="native" />
>>>>>>         </id>
>>>>>>         <property name="Name" column="Name" length="50"
>>>>>> not-null="true" />
>>>>>>     </class>
>>>>>> </hibernate-mapping>
>>>>>>
>>>>>> On Tue, Oct 21, 2008 at 11:13 AM, Gabriel Schenker <
>>>>>> [EMAIL PROTECTED]> wrote:
>>>>>>
>>>>>>> when working uni-directional you have to provide the table name of
>>>>>>> the children (that is the WishList items) in the mapping...
>>>>>>> And about DDD: in the DDD book of Evans he states that
>>>>>>> uni-directional relations are preferable. That does not mean that under
>>>>>>> certain circumstances there shouldn't be a bi-directional relation. As
>>>>>>> always "it depends"
>>>>>>>
>>>>>>>
>>>>>>> On Tue, Oct 21, 2008 at 6:04 PM, Tim Barcz <[EMAIL PROTECTED]>wrote:
>>>>>>>
>>>>>>>> I can make this work if this bidirectional....however I'm needing
>>>>>>>> some guidance as to whether things should be bidirectional or not.  
>>>>>>>> Seems
>>>>>>>> like the domain should dictate, however am not seeing it so simply.
>>>>>>>>
>>>>>>>>
>>>>>>>> On Tue, Oct 21, 2008 at 10:57 AM, Tim Barcz <[EMAIL PROTECTED]>wrote:
>>>>>>>>
>>>>>>>>> Inverse=true give me two sql statements as expected, however it
>>>>>>>>> doesn't include the userId, which leaves my UserId column null (and 
>>>>>>>>> no way
>>>>>>>>> to get the wishlist back for the user).
>>>>>>>>>
>>>>>>>>> NHibernate: INSERT INTO Users (First, Last) VALUES (@p0, @p1);
>>>>>>>>> select SCOPE_IDENTITY(); @p0 = 'Tim', @p1 = 'Barcz'
>>>>>>>>> NHibernate: INSERT INTO WishLists (Name, UserId) VALUES (@p0, @p1);
>>>>>>>>> select SCOPE_IDENTITY(); @p0 = 'Sample', @p1 = ''
>>>>>>>>>
>>>>>>>>> On Tue, Oct 21, 2008 at 10:47 AM, Ayende Rahien <[EMAIL PROTECTED]
>>>>>>>>> > wrote:
>>>>>>>>>
>>>>>>>>>> You need to specify inverse=true
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Tue, Oct 21, 2008 at 5:44 PM, Tim Barcz <[EMAIL PROTECTED]>wrote:
>>>>>>>>>>
>>>>>>>>>>> Ok that's well and good...so I've got unidirectional going
>>>>>>>>>>> on....but am seeing strangeness
>>>>>>>>>>>
>>>>>>>>>>> NHibernate: INSERT INTO Users (First, Last) VALUES (@p0, @p1);
>>>>>>>>>>> select SCOPE_IDENTITY(); @p0 = 'Tim', @p1 = 'Barcz'
>>>>>>>>>>> NHibernate: INSERT INTO WishLists (Name, UserId) VALUES (@p0,
>>>>>>>>>>> @p1); select SCOPE_IDENTITY(); @p0 = 'Sample', @p1 = ''
>>>>>>>>>>> NHibernate: UPDATE WishLists SET UserId = @p0 WHERE WishListId =
>>>>>>>>>>> @p1; @p0 = '8', @p1 = '1'
>>>>>>>>>>>
>>>>>>>>>>> Why does this have to be three calls?  After the first call, the
>>>>>>>>>>> second should have the ID from the first (the userId).  The update 
>>>>>>>>>>> should be
>>>>>>>>>>> unnecessary.
>>>>>>>>>>>
>>>>>>>>>>> Tim
>>>>>>>>>>>
>>>>>>>>>>> On Tue, Oct 21, 2008 at 1:40 AM, Gabriel Schenker <
>>>>>>>>>>> [EMAIL PROTECTED]> wrote:
>>>>>>>>>>>
>>>>>>>>>>>> first of all to decrease complexity I would only use
>>>>>>>>>>>> uni-directional relations in my domain model (even though in the 
>>>>>>>>>>>> database
>>>>>>>>>>>> any relation is bi-directional) that is, a wishlist does not have 
>>>>>>>>>>>> to know
>>>>>>>>>>>> any thing about a user or about its manager
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On Mon, Oct 20, 2008 at 11:16 PM, Tim Barcz <[EMAIL PROTECTED]
>>>>>>>>>>>> > wrote:
>>>>>>>>>>>>
>>>>>>>>>>>>> I have a user object and the user can have a number of
>>>>>>>>>>>>> wishlists.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Instead of having methods on user (ie. User.AddWishlist,
>>>>>>>>>>>>> User.RemoveWishlist), I have a WishListManager which has these 
>>>>>>>>>>>>> methods on
>>>>>>>>>>>>> it.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Persistent entities include, WishList and WishList item, which
>>>>>>>>>>>>> relate back to the user through the WishListManager.
>>>>>>>>>>>>>
>>>>>>>>>>>>> How would I set up this mapping in NHibernate?  Can someone
>>>>>>>>>>>>> point me in the right direction?
>>>>>>>>>>>>>
>>>>>>>>>>>>> Tim
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>>
>>>
>>
>>
>>
>
> >
>

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