Java 类org.hibernate.cfg.AnnotationConfiguration 实例源码

项目:zprojects    文件:HibernateUtil.java   
public static void ReloadConfig() {
    try {
        AnnotationConfiguration config = new AnnotationConfiguration();
        Conexion conn = configDB.config();
         /*
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/zille2</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">infomati</property>*/
        config.setProperty("hibernate.connection.url", 
                "jdbc:mysql://" + conn.getHost() + ":3306/" + conn.getDbname());
        config.setProperty("hibernate.connection.username", conn.getDbuser());
        config.setProperty("hibernate.connection.password", conn.getDbpass());
        System.out.println("Reiniciando configuración hibernate");
        sessionFactory = config.configure().buildSessionFactory();
    } catch (Throwable ex) {
        // Log the exception. 
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
}
项目:class-guard    文件:AnnotationSessionFactoryBean.java   
/**
 * Reads metadata from annotated classes and packages into the
 * AnnotationConfiguration instance.
 */
@Override
protected void postProcessMappings(Configuration config) throws HibernateException {
    AnnotationConfiguration annConfig = (AnnotationConfiguration) config;
    if (this.annotatedClasses != null) {
        for (Class<?> annotatedClass : this.annotatedClasses) {
            annConfig.addAnnotatedClass(annotatedClass);
        }
    }
    if (this.annotatedPackages != null) {
        for (String annotatedPackage : this.annotatedPackages) {
            annConfig.addPackage(annotatedPackage);
        }
    }
    scanPackages(annConfig);
}
项目:web-service-annotation-tool    文件:HibernateUtil.java   
private static SessionFactory buildSessionFactory() {
    try {
        // Create the SessionFactory from hibernate.cfg.xml
        return new AnnotationConfiguration().configure()
                .addAnnotatedClass(AccountModel.class)
                .addAnnotatedClass(RESTServiceModel.class)
                .addAnnotatedClass(ResourceModel.class)
                .addAnnotatedClass(RESTMethodModel.class)
                .addAnnotatedClass(RESTParameterModel.class)
                .addAnnotatedClass(InputMessageModel.class)
                .addAnnotatedClass(InputParameterModel.class)
                .addAnnotatedClass(OutputMessageModel.class)
                .addAnnotatedClass(OutputParameterModel.class)
                .addAnnotatedClass(SOAPOperationModel.class)
                .addAnnotatedClass(SOAPServiceModel.class)
                .buildSessionFactory();//TODO add the rest models here
    }
    catch (Throwable ex) {
        // Make sure you log the exception, as it might be swallowed
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
}
项目:Expert_system    文件:HibernateManager.java   
public static Session getSession()
{
    if (sessionFactory == null)
    {
        synchronized (HibernateManager.class)
        {
            if (sessionFactory == null)
            {
                try
                {
                    log.info("Creating new Content SessionFactory");
                    sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();

                }
                catch (Throwable ex)
                {
                    log.error("Initial Content SessionFactory creation failed.", ex);
                    throw new ExceptionInInitializerError(ex);
                }
            }
        }
    }
    return sessionFactory.openSession();
}
项目:common-security-module    文件:HibernateAnnotationsTest.java   
public void testAnnotated(){
    SessionFactory sf=null;
    AnnotationConfiguration configuration= null;
    String hibernateCfgFileName = "instanceleveltest_annotations.hibernate.cfg.xml";

    configuration = new AnnotationConfiguration().configure(hibernateCfgFileName);
    sf = configuration.buildSessionFactory();



    Session session = null;
    session = sf.openSession();
    Criteria criteria = session.createCriteria(Card.class);
    List l = criteria.list();
    int size = l.size();
    System.out.println("============= Annotated SYSTEM ==================");
    System.out.println("Total no of Cards on which user has access= "+l.size());
    System.out.println("------------------------------------------------------");
    session.close();
    sf.close();

    assertEquals("Incorrect number of cards retrieved",size, 53); // Expecting all cards in the deck including the joker.
}
项目:billiards    文件:MakeTable.java   
/**
     * @param args
     */
    public static void main(String[] args) {
        // Configuration config = new AnnotationConfiguration().configure();

        AnnotationConfiguration config = new AnnotationConfiguration().configure();
        config.addAnnotatedClass(TUser.class)
                .addAnnotatedClass(TGameDetailRecord.class)
                .addAnnotatedClass(TMatch.class)
                .addAnnotatedClass(TMatchType.class)
                .addAnnotatedClass(TResult.class);

/*
        config.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
        new SchemaExport(cfg, connection);*/

        SchemaExport se = new SchemaExport(config);
        se.create(true, true);
    }
项目:labviewer    文件:HibernateHelper.java   
/**
     * Constructor to build the hibernate helper.
     * @param namingStrategy the name strategy, if one is needed, null otherwise.
     * @param interceptor the interceptor, if one is needed, null otherwise.
     */
    public HibernateHelper(NamingStrategy namingStrategy, Interceptor interceptor) {
        try {
            configuration = new AnnotationConfiguration();
            initializeConfig(namingStrategy, interceptor);
            configuration = configuration.configure();
            // We call buildSessionFactory twice, because it appears that the annotated classes are
            // not 'activated' in the config until we build. The filters required the classes to
            // be present, so we throw away the first factory and use the second. If this is
            // removed, you'll likely see a NoClassDefFoundError in the unit tests
            configuration.buildSessionFactory();
            sessionFactory = configuration.buildSessionFactory();
        } catch (HibernateException e) {
//            LOG.error(e.getMessage(), e);
//            throw new ExceptionInInitializerError(e);
            LOG.warn("Failed to initialize HibernateHelper using hibernate.cfg.xml.  "
                    + "This is expected behavior during unit testing." , e);
            e.printStackTrace();
        }
    }
项目:Jouve-Project    文件:EntityManagerUtils.java   
public static void setUp() {        
    AnnotationConfiguration config = new AnnotationConfiguration();
    config.setProperty("hibernate.current_session_context_class", "managed");
    config.setProperty("hibernate.c3p0.max_size", "20").setProperty(
            "hibernate.c3p0.timeout", "3000").setProperty(
            "hibernate.c3p0.idle_test_period", "300").setProperty("hibernate.hbm2ddl.auto", "update");

    ConstellioAnnotationUtils.addAnnotatedClasses(config);

    sessionFactory = config.buildSessionFactory();

    Application.set(new DataDummyWebApplication());

    org.hibernate.classic.Session hibernateSession = sessionFactory.openSession();
    hibernateSession.beginTransaction();
    ManagedSessionContext.bind(hibernateSession);
}
项目:acal    文件:Splash.java   
private  void testarConexao1(){

        new Thread(){
        @Override
        public void run(){
        Session session= null;
        try{

        progress.setString("Testando Conexão com o Banco de Dados");
        session = new AnnotationConfiguration().configure().setProperty("hibernate.connection.username", "root").setProperty("hibernate.connection.password", "123").buildSessionFactory().openSession();

    }catch(HibernateException e){

        JOptionPane.showMessageDialog(null, "Erro de conexão ao banco de dados: "+e.getMessage());
        System.exit(1);
    }finally{
        if(session != null){
            session.close();
        }  
    }

        progress.setString("Conexão bem sucedida...");
        }     
    }.start();    
}
项目:t4f-data    文件:HibernateAbstractClassDFTest.java   
@BeforeClass
public final void pre() {
    injector = Guice.createInjector(PersistenceService.usingHibernate()
        .across(UnitOfWork.TRANSACTION)
        .addAccessor(AbstractWithDF.class)
        .forAll(Matchers.any())

        .buildModule(),

            new AbstractModule() {

                protected void configure() {
                    bind(Configuration.class).toInstance(new AnnotationConfiguration()
                        .addAnnotatedClass(HibernateTestEntity.class)
                        .setProperties(Initializer.loadProperties("spt-persistence.properties")));

                }
            });

    injector.getInstance(PersistenceService.class).start();
}
项目:t4f-data    文件:HibernateDynamicFinderAbstractClassTest.java   
@BeforeMethod
public void pre() {
    injector = Guice.createInjector(PersistenceService.usingHibernate()
            .across(UnitOfWork.TRANSACTION)
            .addAccessor(AbstractDF.class)
            .buildModule(),

            new AbstractModule() {

                protected void configure() {
                    bind(Configuration.class).toInstance(new AnnotationConfiguration()
                        .addAnnotatedClass(HibernateTestEntityTxnal.class)
                        .setProperties(Initializer.loadProperties("spt-persistence.properties")));
                }
            });

    injector.getInstance(PersistenceService.class).start();
}
项目:t4f-data    文件:HibernateDynamicFindersTest.java   
@BeforeClass
public void pre() {
    injector = Guice.createInjector(PersistenceService.usingHibernate()
            .across(UnitOfWork.TRANSACTION)
            .addAccessor(HibernateTestAccessor.class)
            .buildModule(),

            new AbstractModule() {

                protected void configure() {
                    bind(Configuration.class).toInstance(new AnnotationConfiguration()
                        .addAnnotatedClass(HibernateTestEntity.class)
                        .setProperties(Initializer.loadProperties("spt-persistence.properties")));
                }
            });

    injector.getInstance(PersistenceService.class).start();
}
项目:t4f-data    文件:HibernateDynamicFinderWithIsolationTest.java   
@BeforeMethod
public void pre() {
    injector = Guice.createInjector(PersistenceService.usingHibernate()
            .across(UnitOfWork.TRANSACTION)
            .addAccessor(HibernateTestAccessorForDFs.class)
            .buildModule(),

            new AbstractModule() {

                protected void configure() {
                    bind(Configuration.class).toInstance(new AnnotationConfiguration()
                        .addAnnotatedClass(HibernateTestEntityTxnal.class)
                        .setProperties(Initializer.loadProperties("spt-persistence.properties")));
                }
            });

    injector.getInstance(PersistenceService.class).start();
}
项目:t4f-data    文件:ClassLevelManagedLocalTransactionsTest.java   
@BeforeMethod
public void pre() {
    injector = Guice.createInjector(PersistenceService.usingHibernate()
        .across(UnitOfWork.TRANSACTION)
        .forAll(Matchers.annotatedWith(Transactional.class), Matchers.any())
        .buildModule(),
            new AbstractModule() {

                protected void configure() {
                    bind(Configuration.class).toInstance(new AnnotationConfiguration()
                        .addAnnotatedClass(HibernateTestEntity.class)
                        .setProperties(Initializer.loadProperties("spt-persistence.properties")));
                }
            }
    );

    //startup persistence
    injector.getInstance(PersistenceService.class)
            .start();
}
项目:t4f-data    文件:ManualLocalTransactionsWithCustomMatchersTest.java   
@BeforeClass
public void pre() {
    injector = Guice.createInjector(PersistenceService.usingHibernate()
        .across(UnitOfWork.REQUEST)
        .forAll(Matchers.subclassesOf(TransactionalObject.class), Matchers.any())
        .buildModule(),
            new AbstractModule() {

                protected void configure() {
                    bind(Configuration.class).toInstance(new AnnotationConfiguration()
                        .addAnnotatedClass(HibernateTestEntity.class)
                        .setProperties(Initializer.loadProperties("spr-managed-persistence.properties")));
                }
            });

    //startup persistence
    injector.getInstance(PersistenceService.class)
            .start();
}
项目:t4f-data    文件:ManualLocalTransactionsTest.java   
@BeforeClass
public void pre() {
    injector = Guice.createInjector(PersistenceService.usingHibernate()
        .across(UnitOfWork.REQUEST)
        .forAll(Matchers.any())
        .buildModule(),
            new AbstractModule() {

                protected void configure() {
                    bind(Configuration.class).toInstance(new AnnotationConfiguration()
                        .addAnnotatedClass(HibernateTestEntity.class)
                        .setProperties(Initializer.loadProperties("spr-managed-persistence.properties")));
                }
            });

    //startup persistence
    injector.getInstance(PersistenceService.class)
            .start();
}
项目:t4f-data    文件:JoiningLocalTransactionsTest.java   
@BeforeClass
public void pre() {
    injector = Guice.createInjector(PersistenceService.usingHibernate()
        .across(UnitOfWork.TRANSACTION)
        .forAll(Matchers.any())
        .buildModule(),
            new AbstractModule() {

                protected void configure() {
                    bind(Configuration.class).toInstance(new AnnotationConfiguration()
                        .addAnnotatedClass(HibernateTestEntity.class)
                        .setProperties(Initializer.loadProperties("spt-persistence.properties")));
                }
            }
    );

    //startup persistence
    injector.getInstance(PersistenceService.class)
            .start();
}
项目:t4f-data    文件:ManualLocalReadOnlyTransactionsTest.java   
@BeforeClass
public void pre() {
    injector = Guice.createInjector(PersistenceService.usingHibernate()
        .across(UnitOfWork.REQUEST)
        .forAll(Matchers.any())
        .buildModule(),
            new AbstractModule() {

                protected void configure() {
                    bind(Configuration.class).toInstance(new AnnotationConfiguration()
                        .addAnnotatedClass(HibernateTestEntity.class)
                        .setProperties(Initializer.loadProperties("spr-managed-persistence.properties")));
                }
            });

    //startup persistence
    injector.getInstance(PersistenceService.class)
            .start();
}
项目:t4f-data    文件:ManagedLocalTransactionsTest.java   
@BeforeMethod
public void pre() {
    injector = Guice.createInjector(PersistenceService.usingHibernate()
        .across(UnitOfWork.TRANSACTION)
        .forAll(Matchers.any())
        .buildModule(),
            new AbstractModule() {

                protected void configure() {
                    bind(Configuration.class).toInstance(new AnnotationConfiguration()
                        .addAnnotatedClass(HibernateTestEntity.class)
                        .setProperties(Initializer.loadProperties("spt-persistence.properties")));
                }
            }
    );

    //startup persistence
    injector.getInstance(PersistenceService.class)
            .start();
}
项目:t4f-data    文件:HibernateWorkManagerTest.java   
@BeforeClass
public void pre() {
    injector = Guice.createInjector(PersistenceService.usingHibernate()
        .across(UnitOfWork.REQUEST)

        .forAll(Matchers.any())
        .buildModule(),
            new AbstractModule() {

                protected void configure() {
                    bind(Configuration.class).toInstance(new AnnotationConfiguration()
                        .addAnnotatedClass(HibernateTestEntity.class)
                        .setProperties(Initializer.loadProperties("spt-persistence.properties")));
                }
            });

    //startup persistence
    injector.getInstance(PersistenceService.class)
            .start();
}
项目:t4f-data    文件:SessionProvisionTest.java   
@BeforeClass
public void pre() {
    injector = Guice.createInjector(PersistenceService.usingHibernate()
        .across(UnitOfWork.TRANSACTION)
        .forAll(Matchers.any())
        .buildModule(),
            new AbstractModule() {

                protected void configure() {
                    bind(Configuration.class).toInstance(new AnnotationConfiguration()
                        .addAnnotatedClass(HibernateTestEntity.class)
                        .setProperties(Initializer.loadProperties("spt-persistence.properties")));
                }
            });

    //startup persistence
    injector.getInstance(PersistenceService.class)
            .start();
}
项目:t4f-data    文件:ManualLocalTransactionsConfidenceTest.java   
@BeforeClass
public void pre() {
    injector = Guice.createInjector(PersistenceService.usingHibernate()
        .across(UnitOfWork.TRANSACTION)
        .forAll(Matchers.any())
        .buildModule(),
            new AbstractModule() {

                protected void configure() {
                    bind(Configuration.class).toInstance(new AnnotationConfiguration()
                        .addAnnotatedClass(HibernateTestEntity.class)
                        .addAnnotatedClass(HibernateParentTestEntity.class)
                        .setProperties(Initializer.loadProperties("spt-persistence.properties")));
                }
            });

    //startup persistence
    injector.getInstance(PersistenceService.class)
            .start();
}
项目:t4f-data    文件:ReadOnlyTransactionsTest.java   
@BeforeClass
public void pre() {
    injector = Guice.createInjector(PersistenceService.usingHibernate()
        .across(UnitOfWork.TRANSACTION)
        .forAll(Matchers.any())
        .buildModule(),
            new AbstractModule() {
                protected void configure() {
                    bind(Configuration.class).toInstance(new AnnotationConfiguration()
                        .addAnnotatedClass(ReadOnlyTransactionalObject.class)
                        .setProperties(Initializer.loadProperties("spt-persistence.properties")));
                }
            });

    //startup persistence
    injector.getInstance(PersistenceService.class).start();
}
项目:t4f-data    文件:AdvancedTransactionsConfigTest.java   
@BeforeMethod
public void pre() {
    injector = Guice.createInjector(PersistenceService.usingHibernate()
        .across(UnitOfWork.TRANSACTION)
            .forAll(annotatedWith(Transactional.class), any())
            .forAll(not(annotatedWith(Transactional.class)),
                    annotatedWith(Transactional.class))
        .buildModule(),
            new AbstractModule() {

                protected void configure() {
                    bind(Configuration.class).toInstance(new AnnotationConfiguration()
                        .addAnnotatedClass(HibernateAdvancedTxTestEntity.class)
                        .setProperties(Initializer.loadProperties("spt-persistence.properties")));
                }
            }
    );

    //startup persistence
    injector.getInstance(PersistenceService.class)
            .start();
}
项目:wso2-hacks    文件:HibernateUtil.java   
private static SessionFactory buildSessionFactory() {
    try {
        // Create the SessionFactory from hibernate.cfg.xml
        return new AnnotationConfiguration().configure()
                .buildSessionFactory();
    } catch (Throwable ex) {
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
}
项目:trivolous    文件:TestDao.java   
@BeforeClass
    public static void runBeforeClass() throws Exception {
//      ApplicationContext context = 
//          new ClassPathXmlApplicationContext("beans-hibernate.xml");
//      dao = (MemberDao) context.getBean("memberDao");
        Configuration configuration = new AnnotationConfiguration().configure();
        sessionFactory = configuration.buildSessionFactory();
    }
项目:greenpepper    文件:HibernateDatabase.java   
/**
 * <p>Constructor for HibernateDatabase.</p>
 *
 * @param properties a {@link java.util.Properties} object.
 * @throws org.hibernate.HibernateException if any.
 */
public HibernateDatabase(Properties properties) throws HibernateException
{
    cfg = new AnnotationConfiguration();        
    cfg.setProperties(properties); 
    setAnnotadedClasses();
    loadConfig();
}
项目:greenpepper    文件:HibernateDatabase.java   
/**
 * <p>Constructor for HibernateDatabase.</p>
 *
 * @param properties a {@link java.util.Properties} object.
 * @throws org.hibernate.HibernateException if any.
 */
public HibernateDatabase(Properties properties) throws HibernateException
{
    cfg = new AnnotationConfiguration();        
    cfg.setProperties(properties); 
    setAnnotadedClasses();
}
项目:contexttoolkit    文件:HibernateUtils.java   
public static synchronized SessionFactory getSessionFactory() throws HibernateException {
    if (sessionFactory == null) {

        sessionFactory = new AnnotationConfiguration()

        // see http://java.dzone.com/articles/hibernate-3-annotations?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+javalobby%2Ffrontpage+%28Javalobby+%2F+Java+Zone%29
        .addPackage("context.arch.logging.hibernate")
        .addAnnotatedClass(ComponentSubscription.class)
        .addAnnotatedClass(ComponentUpdate.class)
        .addAnnotatedClass(CUAttribute.class)
        .addAnnotatedClass(CUDestination.class)
        .addAnnotatedClass(WidgetRegistration.class)
        .addAnnotatedClass(WRAttribute.class)
        .addAnnotatedClass(WRCallback.class)
        .addAnnotatedClass(WRService.class)
        .addAnnotatedClass(WRServiceFunction.class)
        .addAnnotatedClass(EnactorRegistration.class)
        .addAnnotatedClass(ERParameter.class)
        .addAnnotatedClass(ERReference.class)
        .addAnnotatedClass(ComponentEvaluated.class)
        .addAnnotatedClass(ComponentAdded.class)
        .addAnnotatedClass(CAParamAttribute.class)
        .addAnnotatedClass(ParameterValueChanged.class)
        .addAnnotatedClass(PVCParamAttribute.class)
        .addAnnotatedClass(ServiceExecution.class)
        .addAnnotatedClass(SEInputAttribute.class)

        .buildSessionFactory();

    }
    return sessionFactory;
}
项目:JForum    文件:AbstractDAOTestCase.java   
@Before
public void setUp() throws Exception {
    Configuration config = new AnnotationConfiguration();
    config.configure("/hibernate-tests.cfg.xml");
    sessionFactory = config.buildSessionFactory();
    session = sessionFactory.openSession();
    beginTransaction();
}
项目:ireport-fork    文件:JRHibernateConnection.java   
public SessionFactory getSessionFactory() throws org.hibernate.HibernateException {

          if (useAnnotations)
          {
            AnnotationConfiguration conf = new org.hibernate.cfg.AnnotationConfiguration().configure();
            conf.setProperty(Environment.CONNECTION_PROVIDER, "com.jaspersoft.ireport.designer.connection.HibernateConnectionProvider");
            return conf.buildSessionFactory();
          }
          else
          {
             return new Configuration().configure().buildSessionFactory();
          }
    }
项目:class-guard    文件:AnnotationSessionFactoryBean.java   
@Override
public void setConfigurationClass(Class<?> configurationClass) {
    if (configurationClass == null || !AnnotationConfiguration.class.isAssignableFrom(configurationClass)) {
        throw new IllegalArgumentException(
                "AnnotationSessionFactoryBean only supports AnnotationConfiguration or subclasses");
    }
    super.setConfigurationClass(configurationClass);
}
项目:windup-rulesets    文件:HibernateUtil.java   
public static SessionFactory buildSessionFactoryFromAnnotations()
{
    try
    {
        sessionFactory = new AnnotationConfiguration()
                    .setNamingStrategy(ImprovedNamingStrategy.INSTANCE)
                    .configure("/hib.cfg.xml")
                    .buildSessionFactory();
        return sessionFactory;
    }
    catch (Throwable ex)
    {
        throw new ExceptionInInitializerError(ex);
    }
}
项目:cats    文件:SqlTableCreator.java   
public SqlTableCreator( String packageName ) throws Exception
{
    cfg = new AnnotationConfiguration();
    cfg.setProperty( "hibernate.hbm2ddl.auto", "create" );

    for ( Class< Object > clazz : getClasses( packageName ) )
    {
        cfg.addAnnotatedClass( clazz );
    }
}
项目:AmadeusLMS    文件:ExportBD.java   
public static void main(String[] args) {

    System.out.println("Inicio Export BD");
    Configuration cfg = new AnnotationConfiguration().configure();
    SchemaExport schemaExport = new SchemaExport(cfg);
    schemaExport.create(true,true);
}
项目:zhaoxi    文件:Server.java   
public void init() {
    ins = this;
    logger.debug("Server init");
    AnnotationConfiguration conf = (new AnnotationConfiguration())
            .configure();
    fct = conf.buildSessionFactory();
    service = Executors.newCachedThreadPool();
    scheduledService = Executors.newScheduledThreadPool(5);
}
项目:mechaverse    文件:DatabaseInitialize.java   
public static void main(String args[]) {
  Configuration cfg = new AnnotationConfiguration();
  cfg.configure("hibernate.cfg.xml");

  SchemaExport se = new SchemaExport(cfg);

  se.create(true, true);
}
项目:imobiliariaweb    文件:GerarTabelas.java   
public static void geraTabelas() {
    Configuration cfg = new AnnotationConfiguration();
    cfg.configure("br/com/hslife/imobiliaria/db/hibernate.cfg.xml");

    SchemaExport se = new SchemaExport(cfg);
    se.create(true, true);
}
项目:maven-framework-project    文件:HibernateUtil.java   
private static SessionFactory buildSessionFactory() {
    try {
        // Create the SessionFactory from hibernate.cfg.xml
        return new AnnotationConfiguration()
                .configure()
                .buildSessionFactory();
    } catch (Throwable ex) {
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
}
项目:maven-framework-project    文件:HibernateUtil.java   
private static SessionFactory buildSessionFactory() {
    try {
        // Create the SessionFactory from hibernate.cfg.xml
        return new AnnotationConfiguration()
                .configure()
                .buildSessionFactory();
    } catch (Throwable ex) {
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
}