James Boswell wrote:I agree with Campbell. Instead of calling:
use:
I would remove the getPersonAddress method altogether and implement similar logic in the toString method of Address.
Also, consider the following:
- Rename streetAddress to street within the Address class
- Addresses usually have a house number or name so perhaps houseNumber should be renamed. It should also be a String instead of an int in this case
- As you are using JPA annotations, you should probably consider adding @OneToOne to the address within the Person class
Campbell Ritchie wrote:There is something wrong about having the address field as an Address object, and returning a String from the getAddress method. That breaches the principle that each class takes responsibility for itself. You should have a toString method overridden in the Address class, and the getAddress method should return an Address object.
Bear Bibeault wrote:Where are you getting the NPE? Don't make people guess.