On Mon, 27 Feb 2012 20:55:28 -0300, Ferran Maylinch <ferranmayli...@gmail.com> wrote:

Hello,

Hi!

We are currently using both approaches but we don't know exactly when to
use each one.
When should we inject a HibernateSessionSource into the DAO and create
Sessions with source.create() and when should we directly inject a Session?

Unless in some very specific scenarios, I'd just inject a Session. In Tapestry-Hibernate, Session is a perthread service: in other words, in different threads, different session instances are provided. In the same thread, all Session injections get the same instance.

In our application we have some DAOs calling other DAOs. What should I
inject to them: a HibernateSessionSource or a Session? Or should I pass a
Session to the DAO methods?

Same answer as above: just inject Session.

Or DAOs calling other DAOs is discouraged?

If you're working with two tiers (web and DAO), I'd say no, it isn't discouraged. If you're working with three tiers (web, business rules and DAO), I'd say it is discouraged and you'd better have a business rule class call another one instead.

And a further question would be: what happens if a class starts several
threads using Sessions and transactions. How should we handle that?
Sometimes we suffer deadlocks but we can't spot the cause.

Now you're going out of topic here. IMHO, this is a pure database and connection question, and this is the Tapestry web and IoC framework mailing list. :)

--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to