Reputation: 17487
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
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