Hi all,
i'm writing a reusable component which uses Hibernate for persistance. In general its a simple service which is implemented as a java singleton.
I dont want to make this component a J2EE one (which could configure my persistance stuff of course) or make use of Spring (HibernateTemplate).
For now i only used Hibernate withing Cocoon or Struts ( HibernateFilter pattern ) and use HiberUtil to get the session. This code is of course highly coupled with the web framework.
My current component should use hibernate on its own, without using the Cocoon or Struts HibernateUtil so that it is reusable in any other java application environment.
I wonder about how to instanciate a hibernate-using component best. I thought about following possibilities to inject the hibernate configuration:
* Inject nothing and handle all stuff internally.
- MyComponent.getInstance()
* Inject a SessionFactory
- MyComponent.getInstance( SessionFactory )
* Inject a Session to every method which access the hibernate daos.
- myComponent.getEntities( Session, ... )
* Inject a JDBC Connection (fe from a connection pool) and create a SessionFactory out of it.
- MyComponent.getInstance( Connection, ... )
* Let the component use a kind of HibernateUtilService to get the Session.
- MyComponent#getEntities () {
Session sess = HibernateUtilService.getSession();
...
}
Does anyone has experience with this kind of topic or can point me to a good doc about it?
Thanks,
chris
|