0

What is the best way to store hbm files separately from entity assembly, and load them on demand? I assume I need to load xml file into HbmMapping instance and serialize it into Hibernate.Cfg.Configuration instance?

dbardakov
  • 651
  • 1
  • 8
  • 22
  • What do you mean by "on demand"? You should create NHibernate Session Factory once at application start. After you've created it, I don't think you can modify it. – Daniel Schilling Oct 03 '13 at 16:20
  • Thats true, on-demands=once, but after I do some modification to that xml files. – dbardakov Oct 03 '13 at 16:21

1 Answers1

1

Configuration.AddAssembly(Assembly) is one of the more commonly used methods for loading *.hbm.xml mappings, but it's not the only one. These are all of the "add mappings" methods:

  • AddAssembly
  • AddClass
  • AddDeserializedMapping
  • AddDirectory
  • AddDocument
  • AddFile
  • AddInputStream
  • AddMapping
  • AddResource
  • AddUrl
  • AddXml
  • AddXmlFile
  • AddXmlReader
  • AddXmlString

Assuming you have a method named Stream OpenHbm(String), I believe something like this should work:

foreach (var hbmName in hbmNames)
    using (var stream = OpenHbm(hbmName))
        config.AddInputStream(stream, hbmName);
Daniel Schilling
  • 4,829
  • 28
  • 60