A deadlock can be avoided with a single connection pool too, via proper configuration: For example, Resin's pool (
http://www.caucho.com/resin-3.0/db/config.xtp) supports a "max-overflow-connections" parameter, specifying how many "overflow connections" may be created when a connection wait times out.
So if two main Sessions should block because each is waiting for a sub-connection from a pool that doesn't have any idle connecitons left, they would receive an "overflow connection" after the specified wait time. If no overflow is configured, an exception would get thrown after the wait time - so no deadlock in any case (as far as I see).
The general demarcation problem can be solved by transaction infrastructure through a "transaction suspension" option. EJB CMT offers the transaction attribute "REQUIRES_NEW", which will suspend the current transaction, execute within a new one, then resume the old transaction. If Hibernate Sessions are bound to those transactions, this seems to be exactly what you're trying to achieve.
Of course, with EJB, you'd need to write corresponding Hibernate Session management yourself, because EJB will just care about its JTA transactions.
The upcoming Spring Framework release 1.0 RC1 offers such transaction suspension for POJOs, as a new feature of its generic transaction infrastructure. Resources like Hibernate Sessions are automatically bound to transactions, therefore will get suspended and resumed with transactions. This works with all of Spring's transaction strategies, for example HibernateTransactionManager and JtaTransactionManager.
As a side note, you can use multiple DataSources and multiple SessionFactories in Spring, either each with their own transaction management or with JTA transactions spanning all of them.
Juergen
Spring Framework developer
http://www.springframework.org
http://www.hibernate.org/110.html