HHH-4822 Added handling of sessions == null in case openSession is called

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18604 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Hardy Ferentschik 2010-01-22 02:16:10 +00:00
parent 9bb0da4e69
commit 70ddcd81f2
1 changed files with 13 additions and 1 deletions

View File

@ -53,15 +53,28 @@ public abstract class TestCase extends HibernateTestCase {
}
public Session openSession() throws HibernateException {
rebuildSessionFactory();
session = getSessions().openSession();
return session;
}
public Session openSession(Interceptor interceptor) throws HibernateException {
rebuildSessionFactory();
session = getSessions().openSession( interceptor );
return session;
}
private void rebuildSessionFactory() {
if ( sessions == null ) {
try {
buildConfiguration();
}
catch ( Exception e ) {
throw new HibernateException( e );
}
}
}
protected void setSessions(SessionFactory sessions) {
TestCase.sessions = sessions;
}
@ -72,7 +85,6 @@ public abstract class TestCase extends HibernateTestCase {
@Override
protected void buildConfiguration() throws Exception {
if ( getSessions() != null ) {
getSessions().close();
}