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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:26:40+00:00 2026-06-14T13:26:40+00:00

I have this class Person mapping two tables: Persons and PersonsAUD (audit): <class catalog=test

  • 0

I have this class Person mapping two tables: Persons and PersonsAUD (audit):

 <class catalog="test" name="test.Person" table="Persons" entity-name="Person">
    <id name="id" type="int">
      <column name="Id"/>
      <generator class="increment"/>
    </id>
    <property name="name" type="string">
      <column length="30" name="Name" not-null="true"/>
    </property>
    ...    

  </class>

  <class catalog="test" name="test.Person" table="PersonsAUD" entity-name="PersonAUD">

    <id name="idAudit" type="int">
      <column name="IdAudit"/>
      <generator class="increment"/>
    </id>      

    <property name="name" type="string">
      <column length="30" name="Name" not-null="true"/>
    </property>
    <property name="action" type="string">
      <column length="10" name="Action" not-null="true"/>
    </property>
    ...
  </class>

I’m trying to save this object in the two tables like this:

session.save("Person", person);
session.save("PersonAUD", person);

But only the first row is inserted, not the audit row; probably hibernate check the person’s state and confirms that is already saved.

Any chance to force hibernate to save in both tables the same object?

Thanks in advance.

  • 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-14T13:26:41+00:00Added an answer on June 14, 2026 at 1:26 pm

    I would strongly recommend to NOT to do that. It is very confusing. And not only for Hibernate but later it could bring more problems to you (other developer). To make it more clear, please, let’s try to think about that issue in the POJO entities (not dynamic model)

    Person person = new Person();
    // fill properties
    session.save(person); // as a person
    session.save(person); // as a person audit 
    

    Session will call insert only once, because there is only one instance. One object with one unique identifier. It cannot be evaluated as anything else then a person.

    And the same is happening with your dynamic model. Try to observe your HashMap person after insertion. There should be a key “$type$” which should tell you how is that instance evaluated (as a person). It cannot act as anything else.

    Suggested solution:

    If you need to save one set information into two tables do it with more orientation to ORM style. E.g. clone the person into new HashMap() and save two independent entities

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

Sidebar

Related Questions

I want to mapping a class to a primitive type @Entity @Table(name=PERSON) public class
Good day, I have a hibernate mapping which goes something like this <class name=Person>
I have two simple mappings: <class name="org.testing.Person" table="PERSON"> <id name="personId" type="long" column="PERSON_ID"> <generator class="native"/>
Let's say I have this entity (for Hibernate): @Entity public class Person { @Id
I have a class like this, public class person { name Name {set; get;}
I have a Person and an Organisation Entity: Person looks like this: public class
I have this domain model: class Person < ActiveRecord::Base composed_of :address, mapping: [%w(address_street street),
I have this model : public class Person { public string Name { get;
I have the this objects: class Person { Int32 id; String name; /*..*/ Adress
I have read that this mapping is not possible in NHibernate 3.3: <class name=Digital

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.