<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Note on sets in hibernate/nHibernate</title>
	<atom:link href="http://lostechies.com/joshualockwood/2008/06/05/note-on-sets-in-hibernate-nhibernate/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/joshualockwood/2008/06/05/note-on-sets-in-hibernate-nhibernate/</link>
	<description>Just another LosTechies site</description>
	<lastBuildDate>Wed, 16 Feb 2011 11:54:06 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: temojin</title>
		<link>http://lostechies.com/joshualockwood/2008/06/05/note-on-sets-in-hibernate-nhibernate/#comment-71</link>
		<dc:creator>temojin</dc:creator>
		<pubDate>Tue, 12 Aug 2008 23:30:56 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2008/06/05/note-on-sets-in-hibernate-nhibernate.aspx#comment-71</guid>
		<description>It&#039;s possible to set the index to some arbitrary starting value. The problem i have is when i save the collection, the first row&#039;s index value is set to 0. So when i retrieve the collection (via the owning parent object) i get an array out of bounds exception. 


Has anyone else notice this?
The mapping would look like this:
&lt;list  name=&quot;myCollectionOfThings&quot;  lazy=&quot;true&quot; inverse=&quot;false&quot;  &gt;
 &lt;key&gt;
   &lt;column name=&quot;THING_HOLDER_FK&quot; not-null=true/&gt;
 &lt;/key&gt;
 &lt;list-index column=&quot;SEQUENCE_NUMBER&quot; base=&quot;1&quot;/&gt;
 &lt;one-to-many class=&quot;blah.blablah.ThingHolder&quot;  /&gt;
&lt;/list&gt;


Notice in my case i made the inverse=&quot;false&quot; to let this side manage the persistence of the object (on the many-to-one side i put update=&quot;false&quot; insert=&quot;false&quot;</description>
		<content:encoded><![CDATA[<p>It&#8217;s possible to set the index to some arbitrary starting value. The problem i have is when i save the collection, the first row&#8217;s index value is set to 0. So when i retrieve the collection (via the owning parent object) i get an array out of bounds exception. </p>
<p>Has anyone else notice this?<br />
The mapping would look like this:</p>
<list name="myCollectionOfThings"  lazy="true" inverse="false"  >
 <key></p>
<column name="THING_HOLDER_FK" not-null=true/>
 </key></p>
<list -index column="SEQUENCE_NUMBER" base="1"/>
 <one -to-many class="blah.blablah.ThingHolder"  />
</list>
<p>Notice in my case i made the inverse=&#8221;false&#8221; to let this side manage the persistence of the object (on the many-to-one side i put update=&#8221;false&#8221; insert=&#8221;false&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jlockwood</title>
		<link>http://lostechies.com/joshualockwood/2008/06/05/note-on-sets-in-hibernate-nhibernate/#comment-70</link>
		<dc:creator>jlockwood</dc:creator>
		<pubDate>Fri, 06 Jun 2008 13:55:33 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2008/06/05/note-on-sets-in-hibernate-nhibernate.aspx#comment-70</guid>
		<description>@Ben

Right, I realize that.  As far as the project that I&#039;m working on, the DBA doesn&#039;t want it changed (see my response above).  It&#039;s a little wonky, but I have it working with the way our code is structured.  I&#039;ll change the example now to reduce confusion between this project and the &quot;real world&quot;.  Thanks for the comment!</description>
		<content:encoded><![CDATA[<p>@Ben</p>
<p>Right, I realize that.  As far as the project that I&#8217;m working on, the DBA doesn&#8217;t want it changed (see my response above).  It&#8217;s a little wonky, but I have it working with the way our code is structured.  I&#8217;ll change the example now to reduce confusion between this project and the &#8220;real world&#8221;.  Thanks for the comment!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben Scheirman</title>
		<link>http://lostechies.com/joshualockwood/2008/06/05/note-on-sets-in-hibernate-nhibernate/#comment-69</link>
		<dc:creator>Ben Scheirman</dc:creator>
		<pubDate>Fri, 06 Jun 2008 12:28:18 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2008/06/05/note-on-sets-in-hibernate-nhibernate.aspx#comment-69</guid>
		<description>By definition Sets are not ordered.  What you want is a List, as James Kovacs mentioned above.</description>
		<content:encoded><![CDATA[<p>By definition Sets are not ordered.  What you want is a List, as James Kovacs mentioned above.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jlockwood</title>
		<link>http://lostechies.com/joshualockwood/2008/06/05/note-on-sets-in-hibernate-nhibernate/#comment-68</link>
		<dc:creator>jlockwood</dc:creator>
		<pubDate>Fri, 06 Jun 2008 12:27:23 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2008/06/05/note-on-sets-in-hibernate-nhibernate.aspx#comment-68</guid>
		<description>@Brian
I&#039;ve got good test coverage and all is passing, but I do see what you are saying and will look into it.  I do think that List&lt;&gt; should be used and not Set (usually use list by default with NHiberante).  I&#039;ll go ahead and change the example to reflect this.  I believe I would still need the &#039;order by&#039; in the mapping, right?

@James
I hear you.  As stated above I&#039;ll most likely switch to list.  I really don&#039;t want to implement Comparable right now.  I think the use of set in the first place was wrong, but I see that it resulted from the process used to generate the &#039;Thing&#039; class.

@Sean
I wasn&#039;t aware of that, thanks.  Note that the sequence number in the example above is not a database sequence (like in Oracle).

@All
The app that I&#039;m working on is a little funky and one could argue that the process used in working on the data end is unecessary.  I was trying to minimize needed changes to the hbms because of our process (which I&#039;m hoping to change).

The process is as follows:
0. ValueObjects are created for use in the service layer.
1. Model the DB using Erwin to loosely support the VOs.
2. Generate the DDL&#039;s from the model in Erwin.
3. Generate the hbms from the DDLs.
4. Generate the DataObjects from the hbms.
5. Create conversion classes to map between the VOs and DOs.

I&#039;m new to the project and this is my first go at Hibernate.  I have quite a bit of NHibernate experience under my belt.  The approach we are using is reverse of the process I would normally use (i.e. creating DomainEntities first, then hbms, then schema generation  [DDLs]).  

There&#039;s a huge risk with this approach since every time new hbms are generated to support a VO we need to massage the hbm file.  We try to only generate the hbms/DOs that are needed due to schema changes.  This whole thing is pretty brittle and there&#039;s a huge risk of breaking things with each schema change.

</description>
		<content:encoded><![CDATA[<p>@Brian<br />
I&#8217;ve got good test coverage and all is passing, but I do see what you are saying and will look into it.  I do think that List<> should be used and not Set (usually use list by default with NHiberante).  I&#8217;ll go ahead and change the example to reflect this.  I believe I would still need the &#8216;order by&#8217; in the mapping, right?</p>
<p>@James<br />
I hear you.  As stated above I&#8217;ll most likely switch to list.  I really don&#8217;t want to implement Comparable right now.  I think the use of set in the first place was wrong, but I see that it resulted from the process used to generate the &#8216;Thing&#8217; class.</p>
<p>@Sean<br />
I wasn&#8217;t aware of that, thanks.  Note that the sequence number in the example above is not a database sequence (like in Oracle).</p>
<p>@All<br />
The app that I&#8217;m working on is a little funky and one could argue that the process used in working on the data end is unecessary.  I was trying to minimize needed changes to the hbms because of our process (which I&#8217;m hoping to change).</p>
<p>The process is as follows:<br />
0. ValueObjects are created for use in the service layer.<br />
1. Model the DB using Erwin to loosely support the VOs.<br />
2. Generate the DDL&#8217;s from the model in Erwin.<br />
3. Generate the hbms from the DDLs.<br />
4. Generate the DataObjects from the hbms.<br />
5. Create conversion classes to map between the VOs and DOs.</p>
<p>I&#8217;m new to the project and this is my first go at Hibernate.  I have quite a bit of NHibernate experience under my belt.  The approach we are using is reverse of the process I would normally use (i.e. creating DomainEntities first, then hbms, then schema generation  [DDLs]).  </p>
<p>There&#8217;s a huge risk with this approach since every time new hbms are generated to support a VO we need to massage the hbm file.  We try to only generate the hbms/DOs that are needed due to schema changes.  This whole thing is pretty brittle and there&#8217;s a huge risk of breaking things with each schema change.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean Carpenter</title>
		<link>http://lostechies.com/joshualockwood/2008/06/05/note-on-sets-in-hibernate-nhibernate/#comment-67</link>
		<dc:creator>Sean Carpenter</dc:creator>
		<pubDate>Fri, 06 Jun 2008 11:19:39 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2008/06/05/note-on-sets-in-hibernate-nhibernate.aspx#comment-67</guid>
		<description>Hibernate supports an arbitrary base for &lt;index&gt; by specifying the &quot;base&quot; attribute (it doesn&#039;t have to be zero-based).  NHibernate also supports this in the upcoming 2.0 release (currently in alpha).</description>
		<content:encoded><![CDATA[<p>Hibernate supports an arbitrary base for <index> by specifying the &#8220;base&#8221; attribute (it doesn&#8217;t have to be zero-based).  NHibernate also supports this in the upcoming 2.0 release (currently in alpha).</index></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Kovacs</title>
		<link>http://lostechies.com/joshualockwood/2008/06/05/note-on-sets-in-hibernate-nhibernate/#comment-66</link>
		<dc:creator>James Kovacs</dc:creator>
		<pubDate>Fri, 06 Jun 2008 03:07:44 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2008/06/05/note-on-sets-in-hibernate-nhibernate.aspx#comment-66</guid>
		<description>I&#039;m coming from the NHibernate world, but shouldn&#039;t you be mapping this with a list and using an index element? Order-by is SQL and performs the sort in the database by augmenting the SQL query. This means that items added to the collection won&#039;t be in the proper sort order until persisted and reloaded. Using a &lt;list&gt;, items are always in the proper order.

&lt;list  name=&quot;myCollectionOfThings&quot;  lazy=&quot;true&quot;  inverse=&quot;true&quot;&gt;
  &lt;key&gt;
    &lt;column name=&quot;THING_HOLDER_FK&quot; /&gt;
  &lt;/key&gt;
  &lt;index column=&quot;SEQUENCE_NUMBER&quot;/&gt;
  &lt;one-to-many class=&quot;blah.blablah.ThingHolder&quot;  /&gt;
&lt;/list&gt;

The one limitation is that &lt;index&gt; has to be zero-based. If you don&#039;t have a zero-based index, then I would use the sort attribute on &lt;set&gt; to specify an IComparer to ensure proper ordering.

A quick read over the Hibernate docs seems to confirm that Hibernate has similar facilities though attribute/element names are slightly different in cases. See Hibernate docs section 6.2.3 and &lt;list-index&gt;.</description>
		<content:encoded><![CDATA[<p>I&#8217;m coming from the NHibernate world, but shouldn&#8217;t you be mapping this with a list and using an index element? Order-by is SQL and performs the sort in the database by augmenting the SQL query. This means that items added to the collection won&#8217;t be in the proper sort order until persisted and reloaded. Using a
<list>, items are always in the proper order.</p>
</list>
<list name="myCollectionOfThings"  lazy="true"  inverse="true">
  <key></p>
<column name="THING_HOLDER_FK" />
  </key><br />
  <index column="SEQUENCE_NUMBER"/><br />
  <one -to-many class="blah.blablah.ThingHolder"  />
</list>
<p>The one limitation is that <index> has to be zero-based. If you don&#8217;t have a zero-based index, then I would use the sort attribute on <set> to specify an IComparer to ensure proper ordering.</p>
<p>A quick read over the Hibernate docs seems to confirm that Hibernate has similar facilities though attribute/element names are slightly different in cases. See Hibernate docs section 6.2.3 and
<list -index>.</list></set></index></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Yarger</title>
		<link>http://lostechies.com/joshualockwood/2008/06/05/note-on-sets-in-hibernate-nhibernate/#comment-65</link>
		<dc:creator>Brian Yarger</dc:creator>
		<pubDate>Fri, 06 Jun 2008 02:50:14 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2008/06/05/note-on-sets-in-hibernate-nhibernate.aspx#comment-65</guid>
		<description>In order for this to work, you&#039;ll also need to make sure that the collection class holding &quot;myCollectionOfThings&quot; preserves order.  A HashSet will not, but a LinkedHashSet will, or of course a List would.</description>
		<content:encoded><![CDATA[<p>In order for this to work, you&#8217;ll also need to make sure that the collection class holding &#8220;myCollectionOfThings&#8221; preserves order.  A HashSet will not, but a LinkedHashSet will, or of course a List would.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
