-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Dependecy injection of SessionFactory
PostPosted: Sat May 05, 2007 10:39 am 
Newbie

Joined: Tue Mar 27, 2007 12:42 pm
Posts: 5
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.