Hi, I guess this must be a common problem we all will face sooner or later. In my project, we have a bunch of system wide parameters that are most time read only. The parameters are orginized into tables, say, we group
error codes into a table called "errorCodes" which has two columns:"errorMsg" and "errorCode".
Now my question is, should I use entity bean to represent this table? There are two problems here:
1. since most of the time, the entity bean will return a list of all the errorMsg & errorCodes. it need to have a findAll() method to return a Collection, then the clients will iterate through to get the info, I really don't think it is efficient.
2. we have about 8,9 such tables, I doubt it even make sense to model 8,9 entity beans for each, imagine the client will be mad every time he has to call jndi for a simple parameter.
I am wondering if I can just use stateless session bean, but then since we cannot use static field, how do i cache the data?
I also think about using stateless session bean to read all the entity beans modelled for each table. But that seems complex.
Can somebody share some light with me??
When modelling the System wide parameters that would need to be used across all classes in the application it would be good to use a Properties Java class. It doesnt have to be modelled as an Entity bean since this is not a business entity. It would be correct to model this as a Helper class which provides the required information to the client classes. It can be made as a Singleton class and if you plan to use different sources ( like Databases and Files ) etc to instantiate it, then you can provide a Factory class to instantiate this Helper class. This way you can make it a static class and provide utility static methods for serving out the parameter information to the clients.
Hi, Mr. Kumar, thank you very much for your comments. I also read about the usage of Singleton, but what is a Helper class? And how to use singleton in the context of EJB? Can you give some sample or direct me to some good readings?? Thanks again.
By helper class I am referring to a normal Java class which is accessed from within another Bean. This has all the semantics of a traditional Java class. It can be declared as a static class and provided with a private constructor and an initialize method. I would suggest any good book on Patterns for information regarding Singleton.