[hibernate-commits] Hibernate SVN: r18604 - core/trunk/annotations/src/test/java/org/hibernate/test/annotations.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Jan 21 21:16:10 EST 2010


Author: hardy.ferentschik
Date: 2010-01-21 21:16:10 -0500 (Thu, 21 Jan 2010)
New Revision: 18604

Modified:
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java
Log:
HHH-4822 Added handling of sessions == null in case openSession is called

Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java	2010-01-22 01:55:20 UTC (rev 18603)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java	2010-01-22 02:16:10 UTC (rev 18604)
@@ -53,15 +53,28 @@
 	}
 
 	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 @@
 
 	@Override	
 	protected void buildConfiguration() throws Exception {
-
 		if ( getSessions() != null ) {
 			getSessions().close();
 		}



More information about the hibernate-commits mailing list