-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Saving collections and restricting contents in collections
PostPosted: Tue Aug 09, 2005 3:15 am 
Newbie

Joined: Tue Aug 09, 2005 3:04 am
Posts: 1
A have a couple of issues with a relatively simple data model:

Code:
<class name="DomainModel.Method, DomainModel" table="Method">
  ...
  <bag name="Steps" inverse="true" cascade="all-delete-orphan" order-by="Sequence"> 
    <key column="MethodId"/>
    <one-to-many class="DomainModel.MethodStep, DomainModel" />
  </bag>
</class>

<class name="DomainModel. MethodStep, DomainModel" table="MethodStep">
  ...
   <property name="Sequence" column="Sequence" type="Int32"/>
   <many-to-one name="Method" column=" MethodId " class="DomainModel.Method, DomainModel"/>
   <many-to-one name="Step" column="StepId" class="DomainModel.Step, DomainModel"/>
</class>

<class name="DomainModel.Step, DomainModel" table="Step">
  ...
  <property name="StepType" column="StepType" type="String"/>
  <bag name="MethodSteps" inverse="true" lazy="true">
    <key column="StepId"/>
    <one-to-many class="DomainModel.MethodStep, DomainModel"/>
  </bag>
</class>

A many to many relationship with a join table that also has a Sequence column that is used to order the Method.Steps collection.

All tables have a surrogate primary key which is guids generated by NHibernate.

My problems are:
    1. I work on the Method entity and create, delete and reorder MethodSteps. The cascade attribute makes sure that additions or removal from the collections are persisted. However, when I do a reorder that is lost because the collections are marked as inverse. Is there any way to have it both ways? I tried to remove the inverse=true statement but that does not work well with the all-delete-orphan option.
    2. Method should ideally have two collections instead of just the Steps collection. I would like something similar to:

    Code:
    <bag name="PreSteps" inverse="true" cascade="all-delete-orphan" order-by="Sequence"> 
        <key column="MethodId"/>
        <one-to-many class="DomainModel.MethodStep, DomainModel" />
      </bag>
      <bag name="PostSteps" inverse="true" cascade="all-delete-orphan" order-by="Sequence"> 
        <key column="MethodId"/>
        <one-to-many class="DomainModel.MethodStep, DomainModel" />
      </bag>

    The Step entity has a StepType column which can be either 'Pre' or 'Post'. I would like to have a restriction on the two collections so they only have the 'Pre' steps or the 'Post' steps.

    I have tried to add a "where" attribute to the collection statements but I am having trouble creating a valid statement since the aliases used by the query engine changes sometimes. Sometimes "step0_.StepType='Pre'" will work but at other times is the alias for Step step1_. Is there anyway to let NHibernate know that I refer to the Step entity and let the query engine replace it with the right alias?

    Is there any other way to have the two collections?


Thanks for your time,

HakonB


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.