In your case, don't initialize any session factory, create your two sessions and do :
using(sessionA) {
...query against sessionA
}
using(sessionB) {
...query against sessionA
}
Nesting should also work, i.e :
using(sessionA) {
...query against sessionA
using(sessionB) {
...query against sessionB
}
}
If you want commits or rollback at the end of the block, you can do :
using(sessionA) inTransaction {
...query against sessionA
}
using(sessionB) inTransaction {
...query against sessionA
}
(Notice that it's inTransaction, not transaction, because
the later will make use of Session.concreteFactory which
you'll purposely leave unassigned.
Under the hood, using(s) assigns s as the 'currentSession'
on the thread local storage, so inTransaction will to a commit/rollback
with this 's'. It also puts back the previous 'curent' session on the TLS
if there was one, to ensure that nesting of 'using' is possible
ML