11.1.09

Integrating NHibernate with WPF

A few things to watch out for when you do this integration:

  1. Ensure that the hibernate.cfg.xml file is present.
  2. Set the properties for the hibernate configuration file so that it is always copied to the output folder(bin/debug for debugging),

11-01-2009 20-49-01

failure to do will result in the following error: “An exception occurred during configuration of persistence layer.”

11-01-2009 20-36-18

Converting an XBAP to a WPF application

After starting out on the XBAP route and quickly hitting the sandbox limit it was time to actually move to an application paradigm that would support file access as well as database interaction. So I decided I had to convert the XBAP to a plain old WPF application.

I added a new Window1.xaml file and reconfigured the start url in the App.xaml file to point to the newly added file.

After messing around with  the property sheet for the solution, I proceeded to compile the solution and  instead ended up with the following error message.

11-01-2009 17-42-40

There was not an option to change the setting until I poked in the *.csproj( the project definition file) file which contained the relevant xml nodes <IsWebBootstrapper>, <HostInBrowser> and <TargetZone>. Delete these nodes and F5 the project.

<PropertyGroup>
<
Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<
Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<
SchemaVersion>2.0</SchemaVersion>
<
ProjectGuid>{DDA5DF2A-BCAF-4B2E-9A86-7E7F5F8292C7}</ProjectGuid>
<
OutputType>WinExe</OutputType>
<
AppDesignerFolder>Properties</AppDesignerFolder>
<
RootNamespace>CharityWorkSpace.Zainco.YCW.CRM</RootNamespace>
<
AssemblyName>CharityWorkSpace.YCW</AssemblyName>
<
TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<
FileAlignment>512</FileAlignment>
<
ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<
WarningLevel>4</WarningLevel>
<
EnableSecurityDebugging>true</EnableSecurityDebugging>
<
StartAction>URL</StartAction>
<
HostInBrowser>true</HostInBrowser>
<
TargetZone>Internet</TargetZone>
<
GenerateManifests>false</GenerateManifests>
<
SignManifests>false</SignManifests>
<
ManifestKeyFile>Records Management_TemporaryKey.pfx</ManifestKeyFile>
<
ManifestCertificateThumbprint>3327D64CAF3D6C7423AD45AC8121C526DB8AB168</ManifestCertificateThumbprint>
<
IsWebBootstrapper>true</IsWebBootstrapper>

7.1.09

StaleStateException

NHibernate.StaleStateException: Unexpected row count: 0; expected: 1

at NHibernate.AdoNet.Expectations.BasicExpectation.VerifyOutcomeNonBatched(Int32 rowCount, IDbCommand statement)
at NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation expectation)
at NHibernate.Persister.Collection.AbstractCollectionPersister.Recreate(IPersistentCollection collection, Object id, ISessionImplementor session)
at NHibernate.Action.CollectionRecreateAction.Execute()
at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
at NHibernate.Engine.ActionQueue.ExecuteActions()
at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)
at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)
at NHibernate.Impl.SessionImpl.Flush()
at NHibernate.Transaction.AdoTransaction.Commit()
at Zainco.YCW.Tests.Group.AddYCWGroup() in Group.cs: line 70

This usually means that your database is in an inconsistent state(now say that quickly):

UPDATE MyTable SET Description=’xxxx’  WHERE Id=123;

If an updateable record is not found , then the exception above is thrown. Ensure that you have applied the cascade attribute on the relevant associated objects.

2.1.09

Joined-Subclass exception

NHibernate.MappingException: 'extends' attribute is not found.

at NHibernate.Cfg.XmlHbmBinding.ClassBinder.GetSuperclass(XmlNode subnode)
at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddJoinedSubclasses(XmlNode parentNode)
at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(XmlNode node)
at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)

NHibernate.MappingException: Could not compile the mapping document: Zainco.YCW.Components.Mappings.Member.hbm.xml

at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)
at NHibernate.Cfg.Configuration.ProcessMappingsQueue()
at NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument document)
at NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader, String name)
at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name)
at NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly)
at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly)
at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName)
at NHibernate.Cfg.Configuration.DoConfigure(IHibernateConfiguration hc)
at NHibernate.Cfg.Configuration.Configure()
at Zainco.YCW.Components.Utils.NHibernateHelper.get_Session() in
NHibernateHelper.cs: line 13
at Zainco.YCW.Tests.MemberTest.AddMember() in MemberTest.cs: line 70

If you get this exception then you have probably defined your joined-subclass outside the parent class, which is probably not a good idea if you are aiming to have highly cohesive and modular mapping files. The problem is easily resolved by either adding an extends attribute to the joined-subclass element

<joined-subclass name="KeyLeaderNationalTeamTasks"  table="KeyLeaderNationalTeamTasks" extends="Task">

or nesting the joined-subclass in the class definition.