The Payment class holds a little too much information. Namely, it holds address information and that address data should exist in its own class. Each payment has address data associated with it. This is where we discover Entity relationships.
If you're familiar with object-relational mapping, you may recall that there are at least four types of relationship between classes. In eXtreme Scale terms, the relationships are defined by annotations in the com.ibm.websphere.projector.annotations
package. Those relationships are @OneToOne, @OneToMany, @ManyToOne
, and @ManyToMany
. At first, we'll model the Payment-Address relationship as one-to-one.
First, we'll define the Address class:
@Entity public class Address { @Id private int id; @OneToOne private Payment payment; private String street; private String city; private String state; private String zip; // getters and setters omitted }
The @Entity
and @Id
annotations are familiar. We add the @OneToOne
annotation on the Payment...