Code:
/**
* Return a new Session object that must be closed when the work has been completed.
*
* @param factoryName the config file must match the meta attribute "config-file" in the hibernate mapping file
* @return the active Session
*/
public static Session createSession(String factoryName, Interceptor interceptor) throws HibernateException
{
java.util.Stack sessionStack = (java.util.Stack) threadedSessions.get();
Session session = null;
if (sessionStack == null)
{
sessionStack = new java.util.Stack();
threadedSessions.set(sessionStack);
}
if (sessionStack.size() > 0)
{
Object[] arr = (Object[]) sessionStack.peek();
String cf = (String) arr[0];
if (cf == null)
session = (Session) arr[1];
else if (cf != null && factoryName != null)
{
if (cf.equals(factoryName))
session = (Session) arr[1];
}
if (session == null)
{
if (interceptor != null)
session = getSessionFactory(factoryName).openSession(interceptor);
else
session = getSessionFactory(factoryName).openSession();
arr = new Object[2];
arr[0] = factoryName;
arr[1] = session;
sessionStack.push(arr);
}
}
else
{
if (interceptor != null)
session = getSessionFactory(factoryName).openSession(interceptor);
else
session = getSessionFactory(factoryName).openSession();
Object[] arr = new Object[2];
arr = new Object[2];
arr[0] = factoryName;
arr[1] = session;
sessionStack.push(arr);
}
return session;
}
i open one session without an interceptor and put it back into the stack after using.
on the next methodcall of createSession i will open a session with interceptor. the stack knows there is a opened session and get this one.
there is no chance for me, to set now the given interceptor
any hint ?