01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05:
06: package com.tctest.domain;
07:
08: import org.hibernate.HibernateException;
09: import org.hibernate.SessionFactory;
10: import org.hibernate.cfg.Configuration;
11:
12: public class HibernateUtil {
13:
14: private static SessionFactory sessionFactory;
15: private static final Configuration config;
16:
17: static {
18: config = new Configuration().configure();
19: }
20:
21: public synchronized static SessionFactory getSessionFactory() {
22: if (sessionFactory == null) {
23: try {
24: sessionFactory = config.buildSessionFactory();
25: System.out
26: .println("@@@ sessionFactory identity hash code: "
27: + System
28: .identityHashCode(sessionFactory));
29: } catch (HibernateException ex) {
30: System.err
31: .println("Initial SessionFactory creation failed."
32: + ex);
33: throw new ExceptionInInitializerError(ex);
34: }
35: }
36: return sessionFactory;
37: }
38:
39: public synchronized static void dropAndCreateDatabaseSchema() {
40: config.setProperty("hibernate.hbm2ddl.auto", "create");
41: }
42:
43: }
|