Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Introduction to Spring 2 and JPA

Explore the Spring 2 framework and the Java Persistence API with Eclipse and DB2 Express-C

Sing Li (westmakaha@yahoo.com), Author, Wrox Press
Photo of Sing Li
Sing is a consultant and an active author with over two decades of industry experience. He has contributed to Beginning JavaServer Pages, Professional Apache Tomcat 5, Pro JSP - Third Edition, Early Adopter JXTA, Professional Jini, Beginning J2ME: From Novice to Professional, Third Edition , and numerous other books. Sing also writes for technical magazines and participates in open source communities. He is an evangelist of the open source, VOIP, and P2P movements. You can reach Sing at westmakaha@yahoo.com.

Summary:  Java™ server applications need not be difficult and tedious to create. Now in its second generation, the lightweight Spring framework adds a large suite of features that make it simple for even new server application developers to use. One key enhancement is Spring 2's integration with the Java Persistence API (JPA), a cornerstone of the Enterprise JavaBeans (EJB) 3.0 specification. In this tutorial, learn how to create server applications from scratch using the Spring 2 framework.

Date:  08 Aug 2006
Level:  Introductory PDF:  A4 and Letter (830 KB | 68 pages)Get Adobe® Reader®

Activity:  80074 views
Comments:  

Before you start

For almost a decade, the "proper" way to build a robust and maintainable server-side Java application has been the exclusive domain of the Java 2 Enterprise Edition (J2EE) platform. J2EE applications are built using Enterprise JavaBeans (EJB) technology and run on servers that facilitate deployment and provide rich container services (such as the management of database connections and pooling). These servers also add value by providing deploy-time declarative control of important features such as security and transactions. Although versatile, the J2EE development process involves many tedious and repetitive tasks and the creation and maintenance of large numbers of source code files.

Many lightweight Java frameworks claim to simplify server application development, but none matches the Spring framework in maturity and popularity (see Resources). Now in version 2, Spring was designed from day one to simplify the server application building process. Instead of approaching development from an all-in-one container perspective, Spring aims to provide just enough support for an application's requirements without the burden of a full-fledged container environment. Spring eliminates code bloat: you can code and test business objects completely outside of any container, letting your business-object code remain simple, testable, maintainable, and reusable.

With the arrival of Java EE 5 and EJB 3.0, the J2EE community is poised to meet the Spring developer community. EJB 3.0 supports the notion of lightweight POJOs (Plain Old Java Objects) as EJB components and introduces the Java Persistence API (JPA), a persistence mechanism that can run externally to the container. This persistence mechanism automates the movement of information between business objects and external relational databases. Version 2 of the Spring framework has continued its evolution and also leverages JPA as a persistence mechanism.

In this tutorial, you will work with Spring 2 and JPA persistence. You'll create a server application using the Spring 2 framework, complete with access to a DB2 Express-C database. The Eclipse IDE facilitates the development of the Java application and enhances your exploration of the Spring 2 framework.

About this tutorial

This tutorial aims to guide you through the use and application of the Spring 2 framework in the shortest possible time using a pure and simple learn-by-coding approach. You will build a Web application from scratch, step-by-step, assisted by the Spring 2 framework.

This tutorial does not attempt to cover all of Spring 2's features and options. Instead, it focuses narrowly on one proven approach to server application development using Spring. You are encouraged to consult other Spring 2 resources for more advanced applications and techniques related to the framework (see Resources).

You will proceed through a complete "from concept to application" cycle, including:

  • Performing domain analysis
  • Coding business objects and services
  • Unit testing business objects
  • Adding data access code painlessly to business objects using Spring JPA
  • Implementing your services using Spring DAO (data access object)
  • Coding integration tests for your services against DB2® Express-C
  • Creating controllers for a Spring Model-View-Controller (MVC) based user interface
  • Designing views for the user interface
  • Creating a deployable WAR file of your application
  • Configuring and deploying your application on the Apache Tomcat server

By the end of the tutorial, you'll understand how the Spring 2 framework works and how it can help you create highly componentized and maintainable Web applications. You'll gain working experience in building such an application and can apply many of the techniques you learn here to your daily development tasks.


Prerequisites

You should be familiar with basic object-oriented design concepts and Java development using Java SE 5, including generics. Relational database concepts should be familiar to you, and you should have basic knowledge of how to set up a new database in DB2 Express-C.

Familiarity with testing terminology, including unit testing and integration testing, is assumed. Working experience with test frameworks such as JUnit is desirable, but not required.

You should have working experience with Eclipse and be able to create new Java projects, compile Java code, and debug projects within Eclipse.


System requirements

The required hardware configuration for trying out the tools and example in this tutorial is a system with at least 512MB of memory (1GB recommended).

You need the following software installed:

1 of 15 | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Java technology, Web development
ArticleID=151983
TutorialTitle=Introduction to Spring 2 and JPA
publish-date=08082006
author1-email=westmakaha@yahoo.com
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).