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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:36:59+00:00 2026-06-12T11:36:59+00:00

I have two entities like public class Person { public int PersonId { get;

  • 0

I have two entities like

   public class Person
        {
            public int PersonId { get; set; }
            public string Name { get; set; }
            public int DataId { get; set; }
    }
     public class Data
        {
                public int DataId { get; set; }
        public string details { get; set; }
        public int PersnId{ get; set; }
}

as you see both table are relate to each other. I want a solution to insert data in both table at once. I 1-insert person, 2-insert data and then update person and it works but I’m looking for way to eliminate Update.
My mapping for person table:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="TestNhibrinate" assembly="TestNhibrinate">
    <class name="TestNhibrinate.Entites.Person" table="Person" lazy="false">
        <id name="PersonId" column="PersonId" type="int" >
            <generator class="identity" />
        </id>
        <property name="Name" column="Name" type="String" length="50" />
        <many-to-one name="Adress" class="TestNhibrinate.Entites.Adress" column="AdressId"/>        
    </class>
</hibernate-mapping>

and same mapping for data.

  • 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-06-12T11:37:00+00:00Added an answer on June 12, 2026 at 11:37 am

    You entities should look like this:

           public class Person
                {
                 public Person()
                 {
                    DataCollection = new List<Data>();
                 }
                    public int PersonId { get; set; }
                    public string Name { get; set; }
                    public int DataId { get; set; }
                    public IList<Data> DataCollection{get;set;}
    
                    public void AddData(Data item)
                    {
                       if(!DataCollection.Contains(item))
                       {
                          DataCollection.Add(item);
                       }
                    }
            }
             public class Data
                {
                        public int DataId { get; set; }
                public string details { get; set; }
                public Person Person{ get; set; }
        }
    

    This way you create a one-to-many relation from Person to Data. If you save your person entity after you added some data, the data will also be persisted. This depends on your cascade options offcourse.

    I’m not sure how to map this with XML mappings, since i always use Fluent or Auto mappings.

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

Sidebar

Related Questions

I have two entities like: public class Employee { public int Id { get;
Say I have two Entities. public class Category{ public virtual int Id{get;set;} public virtual
I have two entities like this: public class Service { public virtual int ServiceId
I have two entities: public class Parent() { public ICollection<Child> Children { get; set;
I have two JPA entities: @Entity public class TaskSchedule { ... private String name;
I have two entities: Recipe and Ingredient. Entites: public class Ingredient { public int
I have two entities like the following: @Entity public class Trip { @OneToMany(mappedBy =
I have two entities: ResourceFile: @Entity @Table(name = resource_file) public class ResourceFile extends IdEntity<Integer>
I have a two entities that are related like so. public class User {
I have two entities: public class Tournament { [Key] public Int32 Id { get;

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.