當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。