I am trying to re-create a one-to-one mapping from chapter 8 of the
book "Java Persistence with Hibernate" using the "properties" mapping
element. I have a collection mapped but would also like to select one
item out of the collection, as illustrated in the mapping below.

Is this a use case NHibernate does not currently support? If this
isn't supported what would be the correct method of achieving this?

class Bid {
    public virtual int Id { get; set; }
    public virtual decimal Amount { get; set; }
    public virtual Item Item { get; set; }
    public virtual bool Successful { get; set; }
}

class Item {
    public virtual int Id { get; set; }
    public virtual Bid SuccessfulBid { get; set; }
    public virtual ISet<Bid> Bids { get; set; }

    public Item() {
        this.Bids = new HashedSet<Bid>();
    }
}

<class name="Bid" table="BID">
        <id name="Id" column="BID_ID">
                <generator class="native" />
        </id>
        <property name="Amount" column="AMOUNT" />
        <properties name="successfulReference">
                <property name="Successful" column="SUCCESSFUL" type="YesNo" />
                <many-to-one name="Item" class="Item" column="ITEM_ID" />
        </properties>
</class>

<class name="Item" table="ITEM">
        <id name="Id" column="ITEM_ID">
                <generator class="native" />
        </id>
        <one-to-one name="SuccessfulBid" property-ref="successfulReference">
                <formula>'Y'</formula>
                <formula>ITEM_ID</formula>
        </one-to-one>
        <set name="Bids" inverse="true">
                <key column="ITEM_ID" />
                <one-to-many class="Bid" />
        </set>
</class>

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