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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:02:21+00:00 2026-05-25T22:02:21+00:00

I have a persistent entity that I’m using as a template: Company Locations Departments

  • 0

I have a persistent entity that I’m using as a template:

Company
    Locations
        Departments
            Employees

In other words, a Company contains many Locations, which contains many Departments, which contains many Employees. I have one Company set up as a template that should be copied when a new company is created. However, this template is persistent in the database. I tried using the following code to deep clone it:

var template = EntityLoadByPK("Company", 13);
var company =  Duplicate(template);
EntitySave(company);

But I receive an error says that the entity is not attached to the session. So then I tried to assign 0 to all the IDs before saving:

company.setId(0);
for (location in company.getLocations())
{
    location.setId(0);
    // more nested for loops
}

But I receive a similar error. Finally, I tried to do a direct 1:1 copy of the properties:

var newCompany = EntityNew("Company");
newCompany.setName(company.getName());
newCompany.setCEO(company.getCEO());
// etc...

But this gets more and more cumbersome the deeper the object graph goes. Is there an easier way of deep cloning a persistent entity so that you get a brand new transient entity, including all of its child collections?

  • 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-25T22:02:22+00:00Added an answer on May 25, 2026 at 10:02 pm

    last time I encountered the same situation, I just wrote a clone-like method in the root CFC. Cannot call it clone btw, ’cause it’s reserved I believe.

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

Sidebar

Related Questions

I have Persistent class, referring to many collections with LAZY fetch type, like @Entity
I have a Recipe entity that contains two images: @PersistenceCapable(identityType = IdentityType.APPLICATION, detachable=true) public
I am using GAE(Java) with JDO for persistence. I have an entity with a
I have persistent object, with a string property that often is over 500 charachters.
I am using the SQLite database and have the following persistent class (simplified): public
I have a simple JPA entity that uses a generated long ID as its
I have three classes (House, Room, Address) which are persistent (Mapped with JPA/Hibernate) @Entity
I have an entity Course that has a key to another entity (Document) inside.
i have a persistent entity with a LocalTime field mapped to a time without
I have two value objects, Calendar and Event, that are persistent. Calendar has a

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.