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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access