0
votes

It's possible to override a property Type of a mapping (hbm.xml file, NOT fluent) on NHibernate?

Context: I'm working on application that connects basically on SQL Server (LEGACY DATABASE SCHEMA), but it must work on some Oracle databases too. We've a lot of entities and we've discard to keep two versions of the mapping files, so we decide to define a base mapping (SQL Server) and do some guided modifications in order to work on Oracle (like id generator, column and table names, ...).

Now we've got a new problem with the LONG Oracle fields (LEGACY OBSOLETE FIELD TYPE), it didn't work on NHibernate and we must define a Custom IUserType (http://sonyarouje.com/2012/11/07/nhibernate-and-oracle-long-varchar-field/), this solution is compatible with SQLServer but it requires the DLL Oracle.DataAccess.dll, and in order to avoid this problematic dll we would set this custom type on runtime only when we're connecting on Oracle. But the member Type of Property (NHibernate) is readonly and I haven't found any way to set it.

I'm using NHibernate 3.3.

1

1 Answers

0
votes

We should distinguish ISessionFactory and NHibernate configuration.

In general, we can create as many configurations in runtime, as we want. How to do dynamically is briefly shown here:

3.1. Programmatic Configuration

But once we use the configuration to recieve ISessionFactory - it can not be changed:

An instance of NHibernate.Cfg.Configuration represents an entire set of mappings of an application's .NET types to a SQL database. The Configuration is used to build an (immutable) ISessionFactory. The mappings are compiled from various XML mapping files.

So, I would say, we can in this case create more Factories, from more configurations (which could be pretty dynamically created). And that could solve the issue, based on environment... From some condition/configuration we will know which NHibernate configuration to use... and that will give us appropriate Factory.