當前位置: 首頁>>代碼示例>>Java>>正文


Java AnnotationConfiguration類代碼示例

本文整理匯總了Java中org.hibernate.cfg.AnnotationConfiguration的典型用法代碼示例。如果您正苦於以下問題:Java AnnotationConfiguration類的具體用法?Java AnnotationConfiguration怎麽用?Java AnnotationConfiguration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AnnotationConfiguration類屬於org.hibernate.cfg包,在下文中一共展示了AnnotationConfiguration類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: ReloadConfig

import org.hibernate.cfg.AnnotationConfiguration; //導入依賴的package包/類
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);
    }
}
 
開發者ID:infoINGenieria,項目名稱:zprojects,代碼行數:21,代碼來源:HibernateUtil.java

示例2: postProcessMappings

import org.hibernate.cfg.AnnotationConfiguration; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:20,代碼來源:AnnotationSessionFactoryBean.java

示例3: buildSessionFactory

import org.hibernate.cfg.AnnotationConfiguration; //導入依賴的package包/類
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);
    }
}
 
開發者ID:s-case,項目名稱:web-service-annotation-tool,代碼行數:24,代碼來源:HibernateUtil.java

示例4: getSession

import org.hibernate.cfg.AnnotationConfiguration; //導入依賴的package包/類
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();
}
 
開發者ID:snavruzov,項目名稱:Expert_system,代碼行數:25,代碼來源:HibernateManager.java

示例5: 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

示例6: main

import org.hibernate.cfg.AnnotationConfiguration; //導入依賴的package包/類
/**
	 * @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);
	}
 
開發者ID:linzi-zero,項目名稱:billiards,代碼行數:21,代碼來源:MakeTable.java

示例7: 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

示例8: 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

示例9: testarConexao1

import org.hibernate.cfg.AnnotationConfiguration; //導入依賴的package包/類
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();    
}
 
開發者ID:AlexandrebQueiroz,項目名稱:acal,代碼行數:26,代碼來源:Splash.java

示例10: pre

import org.hibernate.cfg.AnnotationConfiguration; //導入依賴的package包/類
@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();
}
 
開發者ID:xuzhikethinker,項目名稱:t4f-data,代碼行數:22,代碼來源:HibernateAbstractClassDFTest.java

示例11: pre

import org.hibernate.cfg.AnnotationConfiguration; //導入依賴的package包/類
@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();
}
 
開發者ID:xuzhikethinker,項目名稱:t4f-data,代碼行數:19,代碼來源:HibernateDynamicFinderAbstractClassTest.java

示例12: pre

import org.hibernate.cfg.AnnotationConfiguration; //導入依賴的package包/類
@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();
}
 
開發者ID:xuzhikethinker,項目名稱:t4f-data,代碼行數:19,代碼來源:HibernateDynamicFindersTest.java

示例13: pre

import org.hibernate.cfg.AnnotationConfiguration; //導入依賴的package包/類
@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();
}
 
開發者ID:xuzhikethinker,項目名稱:t4f-data,代碼行數:19,代碼來源:HibernateDynamicFinderWithIsolationTest.java

示例14: pre

import org.hibernate.cfg.AnnotationConfiguration; //導入依賴的package包/類
@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();
}
 
開發者ID:xuzhikethinker,項目名稱:t4f-data,代碼行數:21,代碼來源:ClassLevelManagedLocalTransactionsTest.java

示例15: pre

import org.hibernate.cfg.AnnotationConfiguration; //導入依賴的package包/類
@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();
}
 
開發者ID:xuzhikethinker,項目名稱:t4f-data,代碼行數:20,代碼來源:ManualLocalTransactionsWithCustomMatchersTest.java


注:本文中的org.hibernate.cfg.AnnotationConfiguration類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。