Chapter 18. Designing client/server applications
In this chapter
- Patterns for client/server architecture
- Writing and testing a persistence layer
- Integrating EJBs with JPA
Most JPA developers build client/server applications with a Java-based server accessing the database tier through Hibernate. Knowing how the EntityManager and system transactions work, you could probably come up with your own server architecture. You’d have to figure out where to create the EntityManager, when and how to close it, and how to set transaction boundaries.
You may be wondering what the relationship is between requests and responses from and to your client, and the persistence context and transactions on the server. Should a single system transaction handle each client request? Can several consecutive requests hold a persistence context open? How does detached entity state fit into this picture? Can you and should you serialize entity data between client and server? How will these decisions affect your client design?
Before we start answering these questions, we have to mention that we won’t talk about any specific frameworks besides JPA and EJB in this chapter. There are several reasons the code examples use EJBs in addition to JPA:
Path: /apps/app-model/src/main/java/org/jpwh/dao/GenericDAOImpl.java
Path: /apps/app-model/src/main/java/org/jpwh/dao/GenericDAOImpl.java
Path: /apps/app-model/src/main/java/org/jpwh/dao/GenericDAOImpl.java
Path: /apps/app-model/src/main/java/org/jpwh/dao/ItemDAOImpl.java
Path: /apps/app-model/src/main/java/org/jpwh/dao/BidDAOImpl.java
Path: /apps/app-stateless-server/src/test/java/org/jpwh/test/stateless/AuctionServiceTest.java
