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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:29:47+00:00 2026-05-13T05:29:47+00:00

Supposing these are my parent and my child objects: Parent: @Entity @Table( name =

  • 0

Supposing these are my parent and my child objects:

Parent:

@Entity
@Table( name = "import_table" )
public class ImportTable { 
    @Cascade( { CascadeType.ALL, CascadeType.DELETE_ORPHAN } )
    @OneToMany(
        mappedBy = "table",
        fetch = FetchType.EAGER
    )
    public List<ImportTableColumn> getColumns()
    {
        return columns;
    }
    ... setter is defined but I don't think it's important for the example
}

Child:

@Entity
@Table( name = "import_table_column" )
public class ImportTableColumn {
    @ManyToOne
    @JoinColumn(
        name = "import_table_name",
        nullable = false
    )
    public ImportTable getTable()
    {
        return table;
    }
}

The following pseudo-code will work

  • Create instance of ImportTable, add 2 columns, create a session, save it, close the session;
  • Read saved instance in a different session, remove one column;
  • Save it in another session;
  • Check number of columns and is equal to one.

But the following won’t work:

  • Create instance of ImportTable, add 2 columns, create a session, save it, close the session;
  • Read saved instance in a different session;
  • Recreate saved object manually;
  • Remove the column;
  • Save it in another session;
  • Check number of columns and is equal to one.

The reason for this is that we have a Java server/ Flex client application, and we need to load the object, send it to the client, let the client do whatever it has to do, send the object back to the server, and then save it.

I think Hibernate is getting lost when I recreate the object. As far as I know, Hibernate does inject something in the object when it’s retrieved from the database. When I recreate the object, I am not copying anything that is not a declared field in the object class. This is the code to recreate the object (for my unit test):

private ImportTable recreate( ImportTable original ) throws IOException
{
    final ImportTable copy = new ImportTable();
    copy.setDatabaseTableName( original.getDatabaseTableName() );
    copy.setDisplayTableName( original.getDisplayTableName() );
    if( original.getColumns() != null ) {
        copy.setColumns( new ArrayList<ImportTableColumn>( original.getColumns().size() ) );
        for( ImportTableColumn originalColumn : original.getColumns() ) {
            final ImportTableColumn copyColumn = new ImportTableColumn();
            copyColumn.setTable( copy );
            copyColumn.setDatabaseColumnName( originalColumn.getDatabaseColumnName() );
            copyColumn.setDatatype( originalColumn.getDatatype() );
            copyColumn.setExcelColumnName( originalColumn.getExcelColumnName() );
            copyColumn.setId( originalColumn.getId() );
            copyColumn.setLength( originalColumn.getLength() );
            copyColumn.setPk( originalColumn.isPk() );
            copyColumn.setRequired( originalColumn.isRequired() );
            copyColumn.setPrecision( originalColumn.getPrecision() );
            copy.getColumns().add( copyColumn );
        }
    }
    return copy;
}

I believe hibernate is getting lost when I recreate the object. What I want hibernate to do is to compare what is in the database with what is in the object and save the differences only. Is there any way to do that?

  • 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-13T05:29:48+00:00Added an answer on May 13, 2026 at 5:29 am

    Hibernate wraps collection instances into appropriate subclasses of AbstractPersistentCollection when the owner entity is first attached to session.

    That PersistentCollection is then tracking deleted collection elements; without it Hibernate will only be able to perform inserts / updates on them (in most cases; for some id generator classes even that is not possible).

    You’re basically out of luck there; the only thing you can do is to load an existing entity (ImportTable) from the database and modify it (e.g. delete collection elements that are present in loaded copy but not in your clone) then save it.

    That said, I don’t quite follow why you need to clone your entity in the first place (I don’t know Flex … are you marshalling your entity to XML / JSON / etc?) All PersistentCollection implementations are Serializable and thus can be sent over the wire and back. There are ways to marshall them to XML and back as well.

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

Sidebar

Ask A Question

Stats

  • Questions 303k
  • Answers 303k
  • 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 I'm currently using S3 for a project and it's working… May 13, 2026 at 8:35 pm
  • Editorial Team
    Editorial Team added an answer To use the <supports-screen> you have to compile with 1.6… May 13, 2026 at 8:35 pm
  • Editorial Team
    Editorial Team added an answer You can find a AJAX sample here for using a… May 13, 2026 at 8:35 pm

Related Questions

Supposing I was developing a fairly graphically intensive application (C++ or C#, graphics API
Disclaimer : My apologies for all the text below (for a single simple question),
I have the following problem: I have a feed capturer that captures news from
When Joel Spolsky and Jeff Atwood began the disagreement in their podcast over whether

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.