Hi, all. Sorry for yet another long post…
I have a Customer entity (BaseLongIdEntity) with a number of related entities. I want to clone a customer record. If I use the deepCopy() method, which I believe copies my base entity and all related entities, my new Customer has the same ID as my old customer.
How do I get my new Customer to have a new ID - AND - how do I get all the related entities to point to that new ID?
Here is an excerpt from my Customer class showing how my sequence generation is set up. The app is a rewrite of an Oracle Forms 6i app, so I have to use what is in the database.
public class Customers extends BaseLongIdEntity {
@Id
@SequenceGenerator(schema="SBOWNER", name="IDGEN", sequenceName = "IDGEN", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "IDGEN")
@Column(name="ID")
protected Long id;
.
.
.
@OrderBy("directory asc")
@OneToMany(fetch = FetchType.LAZY, mappedBy = "cus")
protected List<Mergedeliv> mergedeliv;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "cus")
protected List<Repdefs> repdefs;
Excerpt from mergedeliv:
public class Mergedeliv extends BaseLongIdEntity {
@Id
@SequenceGenerator(schema="SBOWNER", name="IDGEN", sequenceName = "IDGEN", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "IDGEN")
@Column(name="ID")
protected Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "CUS_ID")
protected Customers cus;
And, worse yet, Composite key in Repdefs (excerpt):
@Embeddable
public class RepdefsCompKey extends EmbeddableEntity {
@Column(name = "CUS_ID")
protected Long cus;
@Column(name = "\"FUNCTION\"")
protected Long function;
@Column(name="REPNUM")
protected Long repnum;
public class Repdefs extends BaseGenericIdEntity<RepdefsCompKey> {
@EmbeddedId
protected RepdefsCompKey id;
@Lookup(type = LookupType.DROPDOWN)
@MapsId("cus")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="CUS_ID")
protected Customers cus;
So, the goal is to make a new Customer that is a copy of the original customer, copy all the related entities, and end up with the new related entities linked to the new customer entity.
Do I have to hard-code the whole thing? There are a LOT of fields and entities.