Pierre Henry
Pierre Henry

Reputation: 17487

How to mix persistent and transient state of a domain object?

I'm looking for a pattern/method do cleanly solve the following problem :

In a on-screen display application (various information is displayed on LCD screens in public places), I have Hibernate persistent POJOs, that can be created and updated in the administration part of my app.

In the "display" part, which is read-only, I use these objects. They must be always up-to-date with the persisted state, but they also have a transient state (that is never stored in the DB) for which the lifespan is the whole user (HTTP) session (can last a whole day or more) and which is specific to each session/user (here a "user" is a screen).

How to (cleanly) combine both states in order to maintain the transient state in-memory (in the HTTP session), while regularly refreshing the persistent state from the DB ? Use the same class and do Hibernate session.refresh() when needed ? Store both states in different classes and link them e.g. with the ID ? Decorator pattern ?

Upvotes: 1

Views: 732

Answers (1)

jpkroehling
jpkroehling

Reputation: 14061

Not sure I understand. If the object is read-only, what kind of information is transient? If the object is read-only, it will always be the same among all sessions. Maybe you mean that the object is not read-only, but it won't be persisted back to the server?

Upvotes: 1

Related Questions