Chapter 3. Persistence pays off
This chapter covers
- The benefits of JDBC and JPA, and why they won’t work in an OSGi environment without help
- How enterprise OSGi and the Apache Aries extensions restore a lovely programming model
- How to read and write from a database in your sample application
- How to use transactions for cleanup when things go wrong
Just as it needs a frontend, every enterprise application needs a backend. For many business applications the heart of the backend is persistence—either read-only access to a directory service, or a full read–write relational data mine, or something in between. This chapter explains how to use persistence and transactions in an enterprise OSGi environment.
Let’s start with a reminder of the persistence options available in Java.
Persistence has been a core part of the Java platform since its introduction. Although the designers of Java didn’t envisage it being used in the kinds of enterprise environments where it’s now common, databases have always been important.
One of the aims of the early Java persistence support was to provide solid abstractions for database access. Databases are notoriously idiosyncratic, and accessing them can be hard work, so it’s an area that benefits from a little help from the platform.