If you are in a managed environment, you could look at attaching the userid to the JTA transaction.
Because I'm in a weblogic environment, I simply used the extention to allows me to set properties against the transaction:
Code:
protected void setTheCuid(String cuid) {
javax.transaction.Transaction tx = TransactionHelper.getTransactionHelper().getTransaction();
Transaction wlstx = (Transaction) tx;
wlstx.setProperty("user", user);
}
Otherwise, you will have to use straight JTA calls to do exactly what getCurrentSession() does.
You will need to maintain a map of transactions to user ids as you get sessions.
You will also need to add yourself as a listener for the transaction complete events so you can remove the transaction->cuid map entries to keep you map size down and allow GC of the transaction objects.