25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9 ■ Adding Persistence to Your <strong>Spring</strong> Application<br />

Figure 9-1. My Documents Relationships<br />

Figure 9-1 shows how the Model classes are related to each other. The Documents table has a one-to-one<br />

relationship with its document type (Types table), and the Users table has a many-to-many relationship with the<br />

Documents table. In other words, a document can have only one type and a user can have many documents.<br />

Now let’s take a look at these classes and the code behind to see the relationship. Let’s start with the Document<br />

class as shown in Listing 9-1.<br />

Listing 9-1. Document.java<br />

package com.apress.isf.java.model;<br />

import java.util.Date;<br />

public class Document {<br />

private String documentId;<br />

private String name;<br />

private Type type;<br />

private String location;<br />

private String description;<br />

private Date created;<br />

private Date modified;<br />

public String getDocumentId() {<br />

return documentId;<br />

}<br />

public void setDocumentId(String documentId) {<br />

this.documentId = documentId;<br />

}<br />

public String getName() {<br />

return name;<br />

}<br />

112

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

Saved successfully!

Ooh no, something went wrong!