HHH-5573 - Change TestCase to rebuildSessionFactory() whenever sessions var is accessed
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@20651 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
bdab36f6f2
commit
0088c9f213
|
@ -55,18 +55,16 @@ 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() {
|
||||
protected SessionFactory getSessions() {
|
||||
if ( sessions == null ) {
|
||||
try {
|
||||
buildConfiguration();
|
||||
|
@ -75,13 +73,6 @@ public abstract class TestCase extends HibernateTestCase {
|
|||
throw new HibernateException( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void setSessions(SessionFactory sessions) {
|
||||
TestCase.sessions = sessions;
|
||||
}
|
||||
|
||||
protected SessionFactory getSessions() {
|
||||
return sessions;
|
||||
}
|
||||
|
||||
|
@ -91,8 +82,8 @@ public abstract class TestCase extends HibernateTestCase {
|
|||
|
||||
@Override
|
||||
protected void buildConfiguration() throws Exception {
|
||||
if ( getSessions() != null ) {
|
||||
getSessions().close();
|
||||
if ( sessions != null ) {
|
||||
sessions.close();
|
||||
}
|
||||
try {
|
||||
setCfg( new AnnotationConfiguration() );
|
||||
|
@ -112,7 +103,7 @@ public abstract class TestCase extends HibernateTestCase {
|
|||
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile );
|
||||
getCfg().addInputStream( is );
|
||||
}
|
||||
setSessions( getCfg().buildSessionFactory( /* new TestInterceptor() */ ) );
|
||||
sessions = getCfg().buildSessionFactory();
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
|
|
Loading…
Reference in New Issue