It is not bad, the problem is that you are trying to make it unidirectional in the wrong direction. The way this works is that the wishlist belongs to a user. This means that you usually have the uni directional from that, and query from the user if you need to. That is a good idea anyway, since that means that you start thinking about things like unbounded result sets.
On Tue, Oct 21, 2008 at 5:54 PM, Tim Barcz <[EMAIL PROTECTED]> wrote: > Below are the mapping files....however the problem I see is that I want to > do a unidirectional mapping. There are two tables (Users and WishLists), of > which WishLists has a foreign-key ref back to users. A Wishlist doesn't > exists outside the context of a user. I'm reading some places where this is > "bad" in NH. I would like to keep this unidirectional as it feels more > correct. > > Suggestions. > > <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" lazy="true"> > <key column="UserId"/> > <one-to-many class="WishList"/> > </bag> > </class> > </hibernate-mapping> > > <?xml version="1.0" encoding="utf-8" ?> > <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" /> > <many-to-one name="Owner" column="UserId" class="User" > not-null="false" /> > </class> > </hibernate-mapping> > > > On Tue, Oct 21, 2008 at 10:46 AM, Gabriel Schenker <[EMAIL PROTECTED]>wrote: > >> show your mappings please >> >> >> 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 -~----------~----~----~----~------~----~------~--~---
