Hello, I have return values, but when I save an object to database and return this then I have those values assigned
//companydata
@Entity
@Setter
@Getter
public class Customer {
@Id
@GeneratedValue(
strategy = GenerationType.AUTO
)
private Long id;
@Embedded
private PersonalData personalData;
@Embedded
private CompanyData companyData;
}
//companydata
@Getter
@Setter
@Embeddable
@EqualsAndHashCode
public class CompanyData {
private String companyName;
@Embedded
@Column(name = "company_address")
private Address address;
@Embedded
@Column(name = "company_contact_data")
private ContactData contactData;
@Nullable private String nip;
@Nullable private String regon;
}
//personaldata
@Getter
@Setter
@EqualsAndHashCode
@Embeddable
public class PersonalData {
private String name, surname;
@Embedded
private Address address;
@Embedded
private ContactData contactData;
private String pesel;
}
Here is return code
public Customer getCustomer(Long customerId){
Optional<Customer> optionalCustomer = customerRepository.findById(customerId);
if (optionalCustomer.isEmpty()) {
throw new ApiNotFoundException("Customer not found");
}
return optionalCustomer.get();
}