jverd wrote:Well Hibernate doesn't but those who create it and use it say the session factory should be a singleton. I looked and looked for a reason why it had to be and the only thing i read was that the factory is heavy and requires a lot of overhead to create while the actual session itself is light so you can create them to your hearts content.
The correct reason to use a Singleton Pattern is because your design calls for a single instance to exists, not for performance reasons.
Where exactly did you get the idea that, "Hibernate expects us to use a singleton session factory because creating factories takes up too much memory or CPU time"?
ttb999 wrote:First that document is referring to a very specific factory. It isn't a reference to all factories.
OK, yes my terminology is imprecise to say the least.
Every source that offers Hibernate tutorials says that the session factory should be a singleton. It seems to only be creating the equivalent of a connection in JDBC.
Can you give me a reason why? The following snippet seems to indicate that it is considered bad form to use anything other than a singleton session factory.