Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1030897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T13:50:37+00:00 2026-05-16T13:50:37+00:00

Is it possible to generate a schema of a database from nHibernate, where I

  • 0

Is it possible to generate a schema of a database from nHibernate, where I have provided nHibernate with the configuration to the database but I have not written any mappings.

I wish to get the Database MetaData/Schema programmatically.

I am using an Oracle Database. I have tried two approaches:

Approach one:

    public DatabaseMetadata GetMetadata(DbConnection connectionIn)
    {
        return new DatabaseMetadata(connectionIn, _dialect);
    }

Problem: This seems to be what I need however, although it correctly connects, it hasn’t picked up any of my tables. All I provided was the nHibernate Configuration object which was populated with the contents of my nHibernate.xml.config file (connection string, driver client, etc).

Question: Why would it not return the table data? It’s connected correctly but finds nothing!

Approach two:

 public void DatabaseSchema()
 {
     var schema = new SchemaExport(nHibernateConfiguration);
     schema.SetOutputFile("schema.dll");
      schema.Create(true, true);
 }

nHibernateConfiguration is an instance (property on class) of the nHibernate Configuration object, populated with contents from the nHibernate.xml.config class.

Problem: This simply doesn’t work. Crashes with the following exception:

NHibernate.MappingException : Dialect
does not support identity key
generation

I suspect this will only generate a schema based on mappings you have created? I have created no mappings. The idea is this will work against whichever database I have connected to a generate a schema for it.

Question: Is my belief that this method will only generate a Schema based on my mappings? If not, Am I using it correctly?

Hopefully this is clear enough, comment if I need to provide more info.

Thanks In Advance.

To be clear: I have a database and want to get meta data representing the database, a schema.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T13:50:37+00:00Added an answer on May 16, 2026 at 1:50 pm

    NHibernate is actually based on the mapping files. You could generate classes or tables from them. There are tools to generate the mapping files, but they are based on the classes, not the tables.

    Answers to your specific questions:

    Approach one: NHibernate does not read table definitions from the database. All the table definitions need to be specified in the mapping files.

    Approach two: SchemaExport creates an SQL file (Create tables, indexes etc) from the mapping definitions. It is actually recommended to use it, unless you need to cope with legacy databases. The output file should be called *.sql, not *.dll.

    The error you get is most probably because you try to create an identity id on an oracle database (or another which does not support identity columns). Use hilo instead (or, if you don’t like it, guid.comb or native). I just wonder why you get this error, I thought that you didn’t write any mapping files?

    Conclusion:

    I don’t know of any tool which create NHibernate mapping files from database tables. There may be one, most probably it is not free or not mature (because otherwise it would be well known). So I suggest to think about generating the table definitions instead, or, in case you have a legacy database, you need to go through writing the mapping files manually.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to generate the database schema from the Nhibernate mappings DLL? My
Is it possible to generate the database tables and c# classes from NHibernate config
Is it possible with datamapper to generate the models from an existing database schema?
Given a [mysql] database with a given schema, is it possible to generate an
I have a database I'd like to create an entity from, and then generate
I am able to generate and export the schema creation script from Fluent Nhibernate.
I use Hyperjaxb3 to generate JPA entities from XSD schema. I have a xsd:string
Is it somehow possible to automatically generate a YAML schema file or models from
Is it possible to generate a XML Schema of a Database programatically with .Net
Is it possible to generate a set of wiki pages from XML comment file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.