10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

public final class LineItemKey implements Serializable {<br />

public Integer orderId;<br />

public int itemId;<br />

}<br />

public LineItemKey() {}<br />

public LineItemKey(Integer orderId, int itemId) {<br />

this.orderId = orderId;<br />

this.itemId = itemId;<br />

}<br />

public boolean equals(Object otherOb) {<br />

if (this == otherOb) {<br />

return true;<br />

}<br />

if (!(otherOb instanceof LineItemKey)) {<br />

return false;<br />

}<br />

LineItemKey other = (LineItemKey) otherOb;<br />

return (<br />

(orderId==null?other.orderId==null:orderId.equals<br />

(other.orderId)<br />

)<br />

&&<br />

(itemId == other.itemId)<br />

);<br />

}<br />

public int hashCode() {<br />

return (<br />

(orderId==null?0:orderId.hashCode())<br />

^<br />

((int) itemId)<br />

);<br />

}<br />

public String toString() {<br />

return "" + orderId + "-" + itemId;<br />

}<br />

Multiplicity in Entity Relationships<br />

<strong>The</strong>re are four types of multiplicities: one-to-one, one-to-many, many-to-one, and<br />

many-to-many.<br />

Entities<br />

Chapter 24 • Introduction to the <strong>Java</strong> Persistence API 687

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!