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

  • SEARCH
  • Home
  • 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 567417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:04:49+00:00 2026-05-13T13:04:49+00:00

Am using the following query to get a Client. The Client has a public

  • 0

Am using the following query to get a Client. The Client has a public Id of type long.

var client = Session.CreateQuery("from Client as c where c.Id = :Id").SetParameter("Id", 1, NHibernateUtil.Int64).UniqueResult<Client>();

Am getting the error:

NHibernate.TypeMismatchException: Provided id of the wrong type. Expected: System.Int32, got System.Int64

At the same time, the following works just fine.

var client = Session.Get<Client>(1L); //Or
var client = Session.CreateCriteria<Client>().Add(Restrictions.Eq("Id", 1L)).UniqueResult<Client>();

What am i missing? Am using fluent nhibernate to create the mappings. I have tested the queries against a Sqlite and a MySql database. Same results.

Edit1: The schema generation from the mappings clearly is using bigint for the primary key on mysql. Thats why i am unable to understand what is expecting a Int32?

Edit2: okay, my Client class has a reference to a Report object. Its actually a one-to-one relationship in the db with the report table having a column clientID. The Report class had an id of type int. Once i changed its type to long, the error went away.

My mappings are as follows:

ClientMap:

HasOne<Report>(x => x.Report)
   .PropertyRef(x => x.Client)
   .LazyLoad()
   .Cascade.SaveUpdate();

ReportMap:

References(x => x.Client, "clientID").Unique();

So, why did the problem solve itself by changing the type of the reportid from int to long. Secondly, why is it even bothering to fetch the report when i am not asking for it?

  • 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-13T13:04:50+00:00Added an answer on May 13, 2026 at 1:04 pm

    One-to-one keys need to have the same type definition since they use the same values. So a Client with ID = Int32.MaxValue + 1 would have a corresponding Report with ID = Int32.MaxValue + 1 so they have to be both long.

    I recommend these articles to understand one-to-one and how most of the time you don’t really need it:

    • http://blog.jagregory.com/2009/01/27/i-think-you-mean-a-many-to-one-sir/
    • http://web.archive.org/web/20100331014510/http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/11/18/legacy-db-and-one-to-one-relations.aspx?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 285k
  • Answers 285k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You are looking for PushbackInputStream Java's IO library is designed… May 13, 2026 at 4:38 pm
  • Editorial Team
    Editorial Team added an answer You can make a curryer, like this: function curry(func) {… May 13, 2026 at 4:38 pm
  • Editorial Team
    Editorial Team added an answer Size is defined as the number of elements in the… May 13, 2026 at 4:37 pm

Related Questions

Recently I have been working with a SQL Server database and I was trying
I am using a MySQL DB and a Java JDBC client to access it.
I just recently moved a SQL DB from SQL2005 32 bit --> 64 bit.
I am writing a custom report from an Avamar (Postgresql) database which contains backup
I am using the following query to get the transactions from a table made

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.