25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Chapter 9<br />

Adding Persistence to Your<br />

<strong>Spring</strong> Application<br />

In this chapter, you are going to add some persistence to your My Documents application. So far you have been using<br />

bean definitions and some hard-coded logic to retrieve information about the documents and types of documents.<br />

For testing purposes, hard-coded data is fine, but in a real-world application like the My Documents <strong>Spring</strong><br />

application, you need some other mechanisms to retrieve all the information because the data can grow and it will be<br />

a hard to keep putting the data in like that.<br />

The <strong>Spring</strong> <strong>Framework</strong> supports a persistence mechanisms using JDBC (Java Database Connectivity) to query,<br />

update, insert, and delete data from databases.<br />

In the My Documents <strong>Spring</strong> application you are going to use a small footprint database engine called the<br />

HSQLDB engine. This engine allows you to run the database in memory. The idea behind using this HSQLDB<br />

database engine is to avoid spending time setting up a database server and trying to configure it, but later in this<br />

chapter you will see how to use different engines such as MySQL (which is one of the most commonly used databases<br />

engines by the open source community).<br />

But enough talk! Let’s see how to add some persistence to your My Documents <strong>Spring</strong> application.<br />

Adding Persistence<br />

First, you are going to modify the Model classes and establish the relationship that you have been adding since the<br />

beginning. Figure 9-1 shows this relationship.<br />

111

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

Saved successfully!

Ooh no, something went wrong!