Name
Serialized Entity Pattern
Goal
To easily persist Java objects to the database.
Participants
- Data object
An object representing some data that we want to store.
- DAO
Uses Java object serialization to translate the object into a set of bytes.
- Database table
Stores the set of bytes.
Interactions
The client passes a data object to a DAO. The DAO uses Java object serialization to translate the object into a set of bytes, which are stored directly in the database. When the client needs to retrieve the object, the DAO reads the bytes back from the database and reconstitutes the object.
Notes
Using serialization has two major drawbacks: the data cannot be queried directly in the database, and the data must be converted if the structure of the underlying objects changes. Using objects that can write themselves to XML alleviates both these concerns.
Get J2EE Design Patterns now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.