I’m happy to announce that the next installment of the Summer of NHibernate screencast series is now available for general download.
In this session we…
- dig into NHibernate’s support for modeling FK-relations between tables in our object model by adding collections that contain other objects
- explore the concepts of Lazy loading and how NHibernate uses proxy objects to defer loading entire deeply-nested object graphs until we ask for them
Unlike some of the immediately-prior sessions, this session contains a bit more Powerpoint content and a bit less interactive coding. As this is our first foray into the quite complicated (and powerful!) universe of NHibernate collection modeling and mapping, there is a (relatively) large amount of new concepts that need to be introduced to lay the groundwork before we can start doing more complex coding exercises with collections and relationships in subsequent sessions.
In addition to understanding and demonstrating the mechanics behind Lazy Loading, this session also provides an overview of the different collection types supported by NHibernate (Sets, Lists, Bags, and Maps) and also covers how we properly ‘escape’ SQL reserved words when they show up in our .hbm.xml mapping files.
As always, comments and feedback are welcomed and appreciated.
Steve,
Just one comment – You rock!
Regards,
Saurabh
Steve,
In particular your explanation of lazy loading is excellent.
Regards
Sunil
@Saurabh
Thanks, I appreciate the praise. I’m glad you’re finding the sessions valuable and helpful.
-Steve B.
@Sunil:
Thanks for the feedback; I’m glad that part came across fairly well. I find that getting devs to properly ‘grok’ lazy-loading is critical to further understanding of most of the more complex NHib stuff to come (caching, collection-management, etc.) as well as troubleshooting what otherwise looks like ‘odd’ behavior with NHib when using it in ‘real life’ apps.
-Steve B.
These are pure gold – I am completely new to NHibernate and I think it will be a good series for my web team to check out to aide in the grok cycle. I hope there is good iSeries support for our DB2 database.
Suggestion – if you publish to a WMV format we all can watch the series at 1.5 speed in WMP and get more in during lunch – also maybe slightly larger fonts.
Hi Steve,
Thanks for the excellent series. I did have a problem with MbUnit; It wouldn’t let me run the tests properly, i.e. the TestFixtureSetup and SetUp would not run (for some reason). I am using Resharper & Testdriven.net but couldn’t get it to work, even with uninstalling R#. Got a strange errormessage that ‘main’ could not be found. Replacing MbUnit with NUnit did work for me.
Tom
@Eric:
I’ll look into both of those suggestions (wmv and fonts); thanks for the feedback.
@Tom:
That’s really odd — I wonder what that issue could be…USUALLY that message sounds to me like its similar to what happens if your cursor is accidentally inside a method in your class-under-test (e.g., the NhibernateDataProvider in this case) rather than your testfixture (e.g., the NHiberrnateDataProviderTest class in this case) when you rt-click and ask TestDriven.NET to run your tests.
The testrunner cannot instantiate its test-fixture class and invoke the MAIN method on it that is (I’m pretty certain) the method that mbunit is using to instantiate an in instance of your test fixture and exectute any method it finds in there that has a [Test] attribute.
Glad you got it running with NUnit, but could you maybe try again with the original un-modified code download and just ensure that you’re properly within the [TestFixture]-attributed class when you invoke TestDrvien.NET to run the tests –?
Just an idea; hope this helps.
I have been running the code downloads with R# 4.0 and the mbunit plugin so far without any dramas. I did try with the galio plugin to start with and got some oddities like the tests would show in the testrunner but not run and or couldn’t be run in debug, but the mbunit plugin seems all good.
@steve b. I know, funny thing is; I’ve tried pc at home and my work. I’m using MbUnit Version 1.0.2700.29885 at work.
Other strange anomaly is that since last night I don’t seem to be able to generate the TestData.xml; the BackupData.xml is created however. A simple rename was sufficient to get it all working again.
I have tried the original download but that didn’t work out for me. Are you using MbUnit for any specific reason (in terms of the training series) over NUnit?
Next to that; will you be covering 1:1 relationships as well in the next one?
@Tom:
re: mbunit vs nunit, no real reason for the choice will be evident in the summer-of-nhibernate screencasts since I don’t (as of now) really intend to use any mbunit-specific capabilities in the series.
In the real-world, I DO have a preference since for quite some time mbunit offered features that nunit lacked (rowtests, etc.). With the recent near-release of nunit 2.5 it sounds to me from the ‘advertised’ feature list that nuninit is moving back closer to feature-parity with mbunit 2.4 so this distinction may start to make less sense.
My present (personal) plan is to wait until both nunit 2.5 and mbunit 3.0 are fully-baked and do a new comparison between them to decide where I (personally) want to go next. I’m somewhat torn between giving my allegience to nunit for their being ‘first’ in .net and blazing the trail the other *Unit frameworks (for .net) have followed in or giving it to mbunit for so effectively pushing the boundaries of ‘accepted’ unit test capabilities (the rowtest, the combinatorial test, etc.)
re: 1:1 relationships, that’s coming in the same segment where we discuss m:n relations (not quite in part 06, but in part 07 it looks like as of now).
Hi Steve.
Problem1:
I have a project where NHib creates the database from mapping file. The problem is that I want to add a ForeignKey without defining any set, map, list or bag. Is that possible?
For example: I have [Warehouse] table and [Transfer] table. I transfer products from one warehouse to another. In [Transfer] I have two columns call [Warehouse_From] and [Warehouse_To]. How can I define in mapping file two ForeignKeys to the parent table [Warehouse]?
Problem2:
Is it possible this kind of relation and how to define it in NHib. I have [Parent] table and [Child] table. I need a foreign key and in the child class I have IList for example.
Thank you!!!
PS: Greetings from Bulgaria.
Problem1 is solved. What about problem2?
@mynkow:
Not sure I understand…is this other than just a has-many relationship –?
Well, actually I did not understand my business guy. So there is no problem. Sorry for the spam 🙂
I’m having a problem at this point. After creating the mapping file for Order, when I run my tests I get 18 out of 23 passed.
The 5 tests failing are throwing the same exception:
NHibernate.HibernateException
Message: Illegal attempt to associate a collection with two open sessions
I don’t understand it. Which 2 open sessions are there?