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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:38:00+00:00 2026-06-15T20:38:00+00:00

I have 2 tables (Customer and CustomerTemp) with same columns. I am retrieving record

  • 0

I have 2 tables (Customer and CustomerTemp) with same columns.
I am retrieving record from Customer table and adding to CustomerTemp table. Retrieved record is stored as custDetails object.
I am using following API:

 void saveOrUpdate(String entityName,
                  Object object)

I have declared 2 entities namely Customer and CustomerTemp using @Entity Annotation. Entity name is used in saveOrUpdate API.

session.saveOrUpdate("CustomerTemp", custDetails); 

to add/update same record into CustomerTemp table. Somehow hibernate is adding/updating record in Customer table.

As per documentation, hibernate should add record to CustomerTemp table. Not sure what is missing.

Update:

For Testing purpose, I have created 2 tables (table1 and table 2)

@Entity(name="mytable1")
public class table1 implements Serializable {
    private static final long serialVersionUID = 3627342236515154416L;

    @Id
    @GeneratedValue
    private int id;

    @Column(length=20)
    private String Name;
          // Getters and setters...
}

@Entity(name="mytable2")
public class table2 implements Serializable {

    private static final long serialVersionUID = -2203149737718957786L;

    @Id
    @GeneratedValue
    private int id;

    @Column(length=20)
    private String Name;
          // Getters and setters...
}

Now I have created object using table1 and tried to use saveOrUpdate with myTable2 entity expecting that record will be saved in table2. But record is always persisted to table1 irrespective of entity name provided in saveOrUpdate.

    Session session = getSessionFactory().getCurrentSession();  
    Transaction tx ;

    table1 tb1 = new table1();
    tb1.setName("Shirish");
    tx = session.beginTransaction();
    session.saveOrUpdate("mytable2", tb1);
    tx.commit();

Regards,
– Shirish

  • 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-15T20:38:02+00:00Added an answer on June 15, 2026 at 8:38 pm

    I am able to use approach specified in question by Cloning java objects. table1 is clone to create new table2 object. But this is really complex process where multiple *-to-Many relations involved.

    Later I have tried to use XML approach to define table in hibernate. Please refer to
    Mapping same POJO to more than one table in Hibernate XML mapping files for details. Please note that you may need to use session.clear() to deattach entity before using it in other DB operation.

    Any other approach will be welcome.

    In this case, Cloning in not required as we are defining tables based on same Java Object.

    Regards,

    Shirish

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

Sidebar

Related Questions

I have 3 tables customer, menu, and order. The order table is suppose to
I have 3 tables: Customer, CustomerTypes, CustomerCustomerTypes. CustomerCustomerTypes is basically is a bridge table
I have two tables Customer and Contract Table CustomerTable CustID(pk) CustName CompanyName ContractTable ContractID(pk)
Let's say i have 2 tables Customer and Books. Table Books can have multiple
I have 2 tables: TABLE customer_service_provider ================================== id | customer | service_provider ================================== 1
I am trying to query top 3 customers. I have 3 tables: Customer table
You have two tables named Customer and SalesOrder. In the Customer table you have
i have 3 tables customer class students ..... this is my table structure: customer
I have the following two tables: Customer { int Id int Name } Bills
I have EF 4 implemented in the project. Within it, there are tables customer

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.