I'm looking for an architecture best practice for persisting singletons with state. I'm sure this comes up often enough, and maybe I'm just too tired to see the obvious solution. An example:
I have a class CCB (change control board, for those not working within bureaucracies):
This should be a singleton, as there is only one CCB. An application admin should be able to change the content of voters through a web interface, and have those changes persisted to a database (I'm using Hibernate).Code:public class CCB { private User chair; private Set<User> voters; // getters & setters }
The solutions that come to mind seem inelegant or restrictive to me. If I didn't need to allow users to modify state, I could create a Spring bean, with a property editor for User, and put it all in an appContext.xml. But that's not an option. I could also give CCB an id property, and hard code that id into the CCB DAO (or put the id into the appContext.xml and inject it into a CCB service bean). Again, seems a little heavy handed.
How is this normally implemented?
Thanks in advance,
Philip


Reply With Quote