Cloning of Address in Hybris

We know that every customer in ecommerce site will have address associated with them.

We also know that cart and order will also have an address which is same as customer address

Cart will have a delivery address which is always referencing the address owned by a Customer
So, whenever customer edits the address, same address will be updated for cart delivery address.
This is because, cart delivery address is obtained by shallow cloning.

Once the cart is converted to an order, the cart address will be cloned and attached to the newly created order.

cloned address in order
is owned by the order and not by the customer which means it does deep cloning.

How to clone address in Hybris?


We can clone address in either of the following 2 ways

1) Shallow cloning
2) Deep cloning

1) Shallow cloning

If we want to clone address and store only reference of the original address then we can do shallow cloning as below

  1. AddressModel clonedAddress = modelService.clone(originalAddress,AddressModel.class);
AddressModel clonedAddress = modelService.clone(originalAddress,AddressModel.class);


In this case, any modification to original address will be reflected in cloned address

Example : Cart delivery address cloned from customer address

2) Deep cloning

If we want to clone address and store it independent of original address then we can do deep cloning as below

  1. AddressModel clonedAddress = addressService.cloneAddress(originalAddress);
AddressModel clonedAddress = addressService.cloneAddress(originalAddress);


Where addressService is an instance of AddressService class

In this case, any modification to original address will not be reflected in cloned address

Example : order delivery address cloned from cart delivery address

Note : One Customer can have any number of addresses.

About the Author

Founder of javainsimpleway.com
I love Java and open source technologies and very much passionate about software development.
I like to share my knowledge with others especially on technology 🙂
I have given all the examples as simple as possible to understand for the beginners.
All the code posted on my blog is developed,compiled and tested in my development environment.
If you find any mistakes or bugs, Please drop an email to kb.knowledge.sharing@gmail.com

Connect with me on Facebook for more updates

Share this article on