Das Blog

Debugging one line at a time
$1*/ mo WordPress hosting! Get going with GoDaddy!
Menu
  • Home
  • Coding
    • Entity Framework
    • MVC
    • NHibernate
  • JavaScript
    • TypeScript
  • Hosting
  • SEO
  • Social
  • Database
    • MySql
    • SSIS
  • WP
  • Other
    • CakePHP
    • Error Messages
    • Google Maps
Home
Coding
NHibernate
NHibernate “hibernate_unique_key doesn’t exist” Error Message
NHibernate

NHibernate “hibernate_unique_key doesn’t exist” Error Message

Codex Discipulus February 21, 2010

The error “Table {Project.DbName}.hibernate_unique_key doesn’t exist” appear after trying to add a record in a newly created Sharp Architecture project using NHibernate map to MySql database server. The database and tables that I was using to add a record from my view existed and were configured correctly. The table had a unique key (“Id”) set to “not null”, “autoincrement” and “Primary Key”.

hibernate_unique_key doesnt exist error

hibernate_unique_key doesnt exist error

After running the code generator (CrudScaffolding project) I ended up with a Core class for my entity (‘User‘ in my case), test class, controller and view pages to perform CRUD operations. The error appeared after I was trying to add a new User using the newly created ADD page and clicked “Save User”.

The solution in my case was simple enough. Sharp MVC Architecture is already wired to use NHibernate and Fluent NHibernate to map the entities to their corresponding database tables. As you can read in the “NHibernate.config” file, Fluent NHibernate is set up in Global.asax.

NHibernate.config Fluent Instruction

NHibernate.config Fluent Instruction

By default your Fluent NHibernate set up in Global.asax will look like this:

Fluent Setup in global.asax

Fluent Setup in global.asax

All the wiring is there. But what was missing was the mapping class. So I wrote a mapping class ‘UserMap‘ to test my mapping for ‘User‘ class in {MyProjectName}.Data.NHibernateMaps

Entity Map class

Entity Map class

After adding the mapping class I rebuilt the project and try to Save a New User again and this time everything was fine. No errors and a New User was created successfully.

Share
Tweet
Google+
Linkedin
Stumble
Email
Prev Article

Related Articles

Working, coding and debugging within Visual Studio environment is very …

MVC + Sharp + IIS7 + NHibernate

4 Common errors when setting up NHibernate 2.01
Installing NHibernate in your application can be challenging. Trying to …

4 Common errors when setting up NHibernate 2.01

About The Author

Codex Discipulus

Hello, my name is David and I am a disciple of coding, always learning and always ready to help. Welcome to my blog, I hope you find it useful, please send your comments and share an article with your friends.

5 Comments

  1. KS

    Thanks for this info. It really helped me a lot.

    If it’s not stretching the friendship, could you possibly show an example of how you create a mapping class where one entity has a field that is mapped to another entity?

    To use your example as a starting point, suppose you had a “UserTypeFk” field in the User class that mapped to another class “UserType”.

    How would you write the “UserMap” mapping class to accommodate that?

    March 23, 2010
    • DaCoder

      Sorry for the delay KS. I am involved almost 90% on this new project. I actually got this code below from the project I am currently working on. This ‘User’ class needs a reference to MembershipPlan entity so we can associate each user with the kind of membership that he/she currently holds (for now, is only PAID and FREE). I hope this helps.


      public class UserMap : IAutoMappingOverride
      {
      public void Override(AutoMap mapping)
      {
      mapping.WithTable("Users");

      mapping.Id(x => x.Id, "UserId")
      .WithUnsavedValue("00000000-0000-0000-0000-000000000000")
      .GeneratedBy.GuidComb();

      mapping.Map(x => x.UserName, "userName").Not.Nullable().WithLengthOf(50);
      mapping.Map(x => x.Email, "email").Not.Nullable().WithLengthOf(40);
      mapping.Map(x => x.FirstName, "firstName").WithLengthOf(50);
      mapping.Map(x => x.LastName, "lastName").WithLengthOf(80);
      mapping.Map(x => x.RegistrationDate, "registrationDate");
      mapping.Map(x => x.UpdatedBy, "updatedBy");
      mapping.Map(x => x.UpdatedByDate, "updatedByDate");
      mapping.Map(x => x.LastLogon, "lastLogon");

      mapping.References(x => x.MembershipPlan, "PlanId").LazyLoad().Cascade.None();
      }
      }

      April 25, 2010
  2. Galen Parker

    bless you mate, this was doing my head in. Trying to learn SharpArch and could not find an answer to this exact problem anywhere. Very grateful.

    May 25, 2010
    • DaCoder

      Excellent!!! I am glad this posts are helping other developers. Thanks a lot for your comment.

      May 25, 2010
  3. DaCoder

    I will definitely will have to take a look at this much cleaner way to fix the issue. Thanks for the help David.

    March 13, 2011

Leave a Reply

Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Hosting ASP.Net Core 3.x Worker Service as …
    Using the Worker template now is possible to host an …
  • Calling an HTTPS WCF Service from Net …
    We all know how to call a WCF service from …
  • How to Add a VS Code Project …
    Let’s try to add a Visual Studio Code project to …
  • Step by Step Token based Authentication in …
    Token Authentication is a very popular method to secure a …
  • How to Ignore NuGet Packages in TFS …
    This should be a short post. It is really just …

Categories

  • CakePHP
  • Coding
  • Database
  • Entity Framework
  • Error Messages
  • General
  • Google Maps
  • Hosting
  • JavaScript
  • MVC
  • MySql
  • Net Core
  • NHibernate
  • SEO
  • SSIS
  • TypeScript
  • Wordpress

Tags

ActiveDirectory analytics apps aspnet CakePHP coding database projects design patterns entity framework error messages fatcow first steps ftp github gitlab godaddy google maps api hangfire Hosting iis7 java javascript membership MVC MySql NHibernate nuget nuget packages oracle owin repository SEO sharp ssis t4 tfs thesis token authentication typescript vs2010 vs2015 vs2017 web api Wordpress wp-pagenavi

Das Blog

Debugging one line at a time
Copyright © 2020 Das Blog
ScottsdaleWebStudio.com © All Rights Reserved 2017