Question

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?

Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top