in

 

Bytes of Wisdom

June 2008 - Posts

  • Note on sets in hibernate/nHibernate

    I just wanted to share this with anyone who is not aware...

    Caveat:  After reviewing my original post and the comments that follow I had initially elected to change the container tag in the example below from set to list.  After thinking about it further I've returned the tag to 'set', since this is after all what I was trying to illustrate in the first place (although understanding the risk of using set should be understood).  Granted, a list probably should have been used, but this was a solution to a problem relating to an existing system that I'm currently working on.  I apologize if it offends your senses, it sort of does mine too, but the tests do pass and the code does work as expected.  Hopefully others facing similar constraints may find it of use in any case.  Smile

    We are using hibernate of my current project, but this should be the same for nHibernate.  In any case, we ran into a situation where we needed to ensure that a collection (Set) on a class that we were mapping needed to ensure the order of list items when used in the middle tier.  The class had a sequenceNumber field that was used to indicate ordinality in the Set.  The knee-jerk solution proposed was to modify the class to support sorting, but it was work that no one wanted to pick up so the code stayed broken.

    I, being industriously lazy, didn't want to do it either but wanted it done none the less.  I had never set the order-by in the hbm configs before but figured this would be as good a reason to use it as any.  So I made one simple change to our mapping file and the broken unit tests magically started passing.  Here's a code example:

    <set name="myCollectionOfThings" lazy="true" inverse="true" order-by="SEQUENCE_NUMBER ASC" > <key> <column name="THING_HOLDER_FK" /> </key> <one-to-many class="blah.blablah.ThingHolder" /> </set>

    It's the "order-by" attribute in the "set" tag is what is used to define the default OrderBy behavior.  The contents are straight SQL that get's tagged on the end of the rendered prepare statement that is executed against the database.

     

    Hope that's of use!

  • Virtual Joy

    At home I have only my Linux box to work with.  I'm quite content with it, but I do have some DOS and older Windows apps that I like to use.  Unfortunately, by DOS floppy's are now dead (as is my floppy drive) and the MSDN DOS download is for making DOS floppies.  What I really wanted was an ISO for DOS that I could use to install on a VM.  Fortunately, I came across FreeDOS (http://www.freedos.org/)!

    FreeDOS is an open source DOS implementation.  It has been around for some time, but I was pretty excited to find it,  It comes with a huge tool set (much more than I need but includes a MASM compatibale assembler, Pascal interpreter, VIM, etc.) and would have been awesome to have in the early 90s.  If you still play DOS games it's a must.

    Just thought I'd share in the event that you aren't aware of this OS.

     

    Side Note:  If you want a floppy boot images for installing Win95/Win98/NT, These guys have them: http://www.allbootdisks.com/

Copyright Los Techies 2007. All rights reserved.
Powered by Community Server (Commercial Edition), by Telligent Systems