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 325377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:12:40+00:00 2026-05-12T09:12:40+00:00

I have a legacy system where the relationship between 2 tables haven’t been defined

  • 0

I have a legacy system where the relationship between 2 tables haven’t been defined explictly and there aren’t any keys (primary or unqiue defined). The only related columns is ‘Username’

Something like:

Table: Customer 
Column: Id,
Column: Username,
Column: FirstName,

Table: Customer_NEW
Column: Username
Column: FirstNameNew

I have following Mapping definitions:

 public sealed class CustomerMap : ClassMap<Customer>, IMap
 {
    public CustomerMap()
    {
        WithTable("customers");
        Not.LazyLoad();
        Id(x => x.Id).GeneratedBy.Increment();
        References(x => x.CustomerNew, "Username")
            .WithForeignKey("Username")
            .Cascade.All();

 }

  public sealed class CustomerNewMap : ClassMap<CustomerNew>, IMap
  {
    public CustomerNewMap()
    {
        WithTable("customers_NEW");
        Not.LazyLoad();
        Id(x => x.Username).GeneratedBy.Assigned();
        Map(x => x.FirstNameNew);
    }
  }

The problem is nHibernate is generating an UPDATE statement for the ‘Reference’ in the Customer Mapping definition which is obviously failing when attempting to insert a new Customer object which has a reference to CustomerNew object.

How do I get the mapping definition to generate the INSERT statement instead of an UPDATE for the ‘Save’ command?

Cheers in advance

Ollie

  • 1 1 Answer
  • 3 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-12T09:12:41+00:00Added an answer on May 12, 2026 at 9:12 am

    The reason is because there isn’t any referential integrity in the database, no primary keys, composite keys not foreign key constraints…

    Yet again another application that has a database that’s not fit for purpose…

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

Sidebar

Related Questions

Hi I'm using ms2005 for a simple calendaring system. We have three 'legacy' tables:
I have been tasked with making some edits to a legacy system that is
I have a paradox table from a legacy system I need to run a
At my place of work we have a legacy document management system that for
I have legacy system where all date fields are maintained in YMD format. Example:
We have a legacy system that is essentially a glorified telnet interface. We cannot
We have a legacy system consists of class A, B and C. A is
I currently have a legacy system that uses SPs exclusively for access to the
I have a situation with a legacy system which uses Java EE Bean Managed
In one project we have a dependency on a legacy system and its .Net

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.