当前位置: 首页>>代码示例>>Java>>正文


Java AnnotationConfiguration.buildSessionFactory方法代码示例

本文整理汇总了Java中org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationConfiguration.buildSessionFactory方法的具体用法?Java AnnotationConfiguration.buildSessionFactory怎么用?Java AnnotationConfiguration.buildSessionFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.cfg.AnnotationConfiguration的用法示例。


在下文中一共展示了AnnotationConfiguration.buildSessionFactory方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testAnnotated

import org.hibernate.cfg.AnnotationConfiguration; //导入方法依赖的package包/类
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.
}
 
开发者ID:NCIP,项目名称:common-security-module,代码行数:24,代码来源:HibernateAnnotationsTest.java

示例2: HibernateHelper

import org.hibernate.cfg.AnnotationConfiguration; //导入方法依赖的package包/类
/**
     * 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();
        }
    }
 
开发者ID:NCIP,项目名称:labviewer,代码行数:25,代码来源:HibernateHelper.java

示例3: setUp

import org.hibernate.cfg.AnnotationConfiguration; //导入方法依赖的package包/类
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);
}
 
开发者ID:BassJel,项目名称:Jouve-Project,代码行数:18,代码来源:EntityManagerUtils.java

示例4: getSessionFactory

import org.hibernate.cfg.AnnotationConfiguration; //导入方法依赖的package包/类
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();
          }
    }
 
开发者ID:JockiHendry,项目名称:ireport-fork,代码行数:14,代码来源:JRHibernateConnection.java

示例5: init

import org.hibernate.cfg.AnnotationConfiguration; //导入方法依赖的package包/类
public void init() {
	ins = this;
	logger.debug("Server init");
	AnnotationConfiguration conf = (new AnnotationConfiguration())
			.configure();
	fct = conf.buildSessionFactory();
	service = Executors.newCachedThreadPool();
	scheduledService = Executors.newScheduledThreadPool(5);
}
 
开发者ID:yufenghua,项目名称:zhaoxi,代码行数:10,代码来源:Server.java

示例6: buildSessionFactory

import org.hibernate.cfg.AnnotationConfiguration; //导入方法依赖的package包/类
private static SessionFactory buildSessionFactory() {
	try {
		AnnotationConfiguration cfg = new AnnotationConfiguration();
		cfg.configure("hibernate.cfg.xml");
		return cfg.buildSessionFactory();
	} catch (Throwable e) {
		System.out.println("Criação inicial do objeto SessionFactory falhou. Erro: " + e);
		throw new ExceptionInInitializerError(e);
	}
}
 
开发者ID:vaglucas,项目名称:cafeUnoesc,代码行数:11,代码来源:HibernateUtil.java

示例7: getSession

import org.hibernate.cfg.AnnotationConfiguration; //导入方法依赖的package包/类
public static Session getSession() {
	AnnotationConfiguration conf = new AnnotationConfiguration();
	conf.configure();
	
	SessionFactory factory = conf.buildSessionFactory();
	Session session = factory.openSession();
	return session;
}
 
开发者ID:lucasaquiles,项目名称:saci-biblio-service,代码行数:9,代码来源:CriadorDeSession.java

示例8: DAOFactory

import org.hibernate.cfg.AnnotationConfiguration; //导入方法依赖的package包/类
private DAOFactory() {
	AnnotationConfiguration cfg = new AnnotationConfiguration();

	cfg.addAnnotatedClass(Topography.class);
	cfg.addAnnotatedClass(TopographyCategory.class);
	cfg.addAnnotatedClass(TopographyGroup.class);

	cfg.addAnnotatedClass(Morphology.class);
	cfg.addAnnotatedClass(MorphologyGroup.class);

	cfg.addAnnotatedClass(RHC.class);
	cfg.addAnnotatedClass(DCE.class);
	cfg.addAnnotatedClass(SighReport.class);
	cfg.addAnnotatedClass(Patient.class);
	cfg.configure();

	// TODO set fetch size according to Constants.BATCH_SIZE

	if (Constants.RECREATE_DB) {
		SchemaExport se = new SchemaExport(cfg);
		se.create(true, true);
	}

	this.sessionFactory = cfg.buildSessionFactory();

	for (int i = 0; i < CONNECTIONS; i++)
		session[i] = sessionFactory.openSession();

	for (int i = 0; i < CONNECTIONS; i++)
		topographyDAO[i] = new TopographyDAO(session[i]);
	for (int i = 0; i < CONNECTIONS; i++)
		topographyCategoryDAO[i] = new TopographyCategoryDAO(session[i]);
	for (int i = 0; i < CONNECTIONS; i++)
		topographyGroupDAO[i] = new TopographyGroupDAO(session[i]);

	for (int i = 0; i < CONNECTIONS; i++)
		morphologyDAO[i] = new MorphologyDAO(session[i]);
	for (int i = 0; i < CONNECTIONS; i++)
		morphologyGroupDAO[i] = new MorphologyGroupDAO(session[i]);

	for (int i = 0; i < CONNECTIONS; i++)
		dceDAO[i] = new DceDAO(session[i]);
	for (int i = 0; i < CONNECTIONS; i++)
		sighDAO[i] = new SighDAO(session[i]);
	for (int i = 0; i < CONNECTIONS; i++)
		rhcDAO[i] = new RhcDAO(session[i]);
	for (int i = 0; i < CONNECTIONS; i++)
		patientDAO[i] = new PatientDAO(session[i]);
}
 
开发者ID:michelole,项目名称:ICDClassifier,代码行数:50,代码来源:DAOFactory.java


注:本文中的org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。