1
votes

I am using Fluent NHibernate (which I am fairly new to) in an application I am developing using a legacy Oracle DB. The DB has composite keys which are comprised of foreign keys and database generated columns. The generated columns are supplied by calling a DB function with the table name, and one of the other foreign key parts. The generated composite key parts are not unique, and I cannot change this. The generated key parts are often used as foreign keys on other tables too.

If I create entity mapping which specifies the composite key as it is in the database, then we cannot use any identity generation strategies, which breaks unit of work

If I create entity mapping which specifies only the generated column as the primary key, then I can use trigger-identity to generate the ids, and I get unit of work, but I then have a problem when I want to update, or access a child collection: The other parts of the key are not included in the WHERE statement.

Can anyone give me any advice on how to proceed?

  • If I stick with mapping composite keys, can I extend nhibernate to output the SQL to use trigger-identity? If so, can you suggest a starting point?
  • If I map a single column key, can I include other properties in a WHERE clause for HasMany mapping and Updates?
1
you could try <composite-id><column ... generated="true" />...Firo
@Firo, I dont think this is possible with Fluent NHibernate. If XML mapping is used, will this output the SQL statements to return the generated id, and use it for foreign keys do you htink?TimC
AFAIK FNH has .Generated(), have to checkFiro
@Firo: Yes, there is a .Generated() method available, but not for CompositeId(). I have resolved the issue now. Will post an edit with the solution.TimC

1 Answers

1
votes

Unfortunately, as you have already found out, there is no support at all for this setup.

My suggestion is to do INSERTS manually (using custom SQL, for example). And yes, this breaks the UoW, but that is true of identity too.