background image

Multiplicity in Entity Relationships

<< Primary Keys in Entities | Direction in Entity Relationships >>
<< Primary Keys in Entities | Direction in Entity Relationships >>

Multiplicity in Entity Relationships

public final class LineItemKey implements Serializable {
public Integer orderId;
public int itemId;
public LineItemKey() {}
public LineItemKey(Integer orderId, int itemId) {
this.orderId = orderId;
this.itemId = itemId;
}
public boolean equals(Object otherOb) {
if (this == otherOb) {
return true;
}
if (!(otherOb instanceof LineItemKey)) {
return false;
}
LineItemKey other = (LineItemKey) otherOb;
return (
(orderId==null?other.orderId==null:orderId.equals
(other.orderId)
)
&&
(itemId == other.itemId)
);
}
public int hashCode() {
return (
(orderId==null?0:orderId.hashCode())
^
((int) itemId)
);
}
public String toString() {
return
"" + orderId + "-" + itemId;
}
}
Multiplicity in Entity Relationships
There are four types of multiplicities: one-to-one, one-to-many, many-to-one, and
many-to-many.
Entities
Chapter 24 · Introduction to the Java Persistence API
689