This is a mirror of official site: http://jasper-net.blogspot.com/

Tweaking NHibernate Mappings at Runtime With a Remapper

| Sunday, September 11, 2011
Every once in a while, especially on legacy systems, you can run into database-specific issues that NHibernate can't get around out of the box. We've been looking to convert from our current ORM to NHibernate, and run into a couple. One is self-inflicted (we use a DB-first codegen approach) and the other is forced on us by differences in the way Oracle and SQL Server handle ID assignment. So our problems are:

    NHibernate defaults to a single global sequence on Oracle - we need a named sequence per table
    Table names on oracle can't exceed 30 characters

We really don't want to compile mappings into their own assembly (really 2, that we could switch between), so we looked for alternatives and found a Remapper approach on Krystof Kozmic's blog. In a nutshell, this allows you to adjust your (single set of) mappings at runtime to account for platform-specific bits.

So let's take a quick look at how these problems can be addressed.  First step is to find out if we're running against Oracle (we are lucky enough to be able to assume SQL Server if it's not Oracle,  so it's a bit easier).  This can be done by examining the Properties dictionary on the configuration (in this case, in the remapper's constructor):

    Remapper (Configuration configuration) {
        config = configuration;
        isOracle = config.Properties["dialect"].ToLower ().Contains ("oracle");
    }

Read more: Less than dot
QR: tweaking-nhibernate-mappings-at-runtime

Posted via email from Jasper-net

0 comments: