AlexCuse
AlexCuse

Reputation: 18296

Remapping NHibernate ID Generation

We have an application that currently supports Oracle and SQL Server databases. We're in the process of moving to NHibernate from another ORM.

Our ID mappings (for oracle) end up looking like this:

<id name="Id" column="FoozId">
  <generator class="native">
    <param name="sequence">Fooz_SEQ</param>
  </generator>
</id>

We can't simply use "native" because this uses a single database-wide sequence, and we need one per entity type.

We are trying to use the remapper idea discussed here, and it seems to work well enough for things like trimming table names that are longer than thirty characters, etc... But we can't figure out how to remove the sequence param from our mappings as we pass them through. We still want to use the native generator class for SQL Server, but omitting the sequence name.

Is this going to be doable, or are we going to need to generate two sets of mappings?

Upvotes: 0

Views: 189

Answers (1)

AlexCuse
AlexCuse

Reputation: 18296

This seems to work in a test project we set up:

if (classMap.Identifier.IsSimpleValue) {
    var simpleVal = classMap.Identifier as SimpleValue;
    simpleVal.IdentifierGeneratorProperties.Remove("sequence");
}

Not sure if it's the best way to do it, but it does have some simple integration tests passing against a SQL Server database with Oracle mappings.

Upvotes: 1

Related Questions