// Copy sub-product data if there is any:
if (sub.getDerivedProduct() != null) {
p.setDerivedProductId(sub.getDerivedProduct().getId());
p.setDerivedProductName(sub.getDerivedProduct().getName());
for (ProductAttribute attr : sub.getDerivedProduct().getAttributes()) {
p.addSubProductAttribute(new DerivedProductPoolAttribute(attr.getName(),
attr.getValue(), sub.getProduct().getId()));
}
}
for (Product prod : sub.getProvidedProducts()) {