Copy not null and not empty fields from one object to another object of the same type(Objects are same type) in java
        Posted  
        
            by 
                Chinni
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Chinni
        
        
        
        Published on 2012-04-05T09:52:38Z
        Indexed on 
            2012/04/05
            11:29 UTC
        
        
        Read the original article
        Hit count: 182
        
I am using hibernate, struts, extjs in my project.
I have a Customer object with these fields:
custId,
custName, address, phone
and in my project from UI side I get an object customer with custName.
So I need to update the above object(custName is unique). I have only one object with the same customer name. So I will get that object using customer name (object from DB).
Now I have to save the object with the updated customer name.
If I save as follows I have Customer Object from UI, is cust
Customer cust1 = getCustomerByName(cust.getCustName());
cust.setCustId(cust1.getCustId()); save(cust);
If I do this I lose the customer address and phone number.
So, how can I copy one object not null or not empty field values to another object of same type.
Can any one please help. I just stuck here. It's stopping me to save.
Thanks in advance!
© Stack Overflow or respective owner