Hibernate ORM AnnotationConfiguration - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Hibernate ORM AnnotationConfiguration class.

This code example shows how to use the following methods:configure, buildSessionFactory
	/** 
	 * Getting a real Hibernate Session, from a memory database. 
	 */ 
	@Before 
	public void setUp() throws Exception {
		AnnotationConfiguration cfg = new AnnotationConfiguration();
		cfg.configure().setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:mydvdsDB");
		session = cfg.buildSessionFactory().openSession();
		session.beginTransaction(); 
		dao = new DefaultDvdDao(session);
	} 
 
 
	/** 
	 * Undoing all changes to database 
	 * @throws Exception 
	 */ 
	@After 
	public void tearDown() throws Exception {
		if (session != null && session.getTransaction().isActive()) { 
7
CodeRank
This code example shows how to use the following methods:configure, setProperties, buildSessionFactory, addFilterDefinition
            File testCfg = ResourceUtils.getFile("classpath:hibernate.cfg.xml");
            File mockFilter = ResourceUtils
                    .getFile("classpath:mock_filters.hbm.xml"); 
            Properties props = new Properties();
            props.load(new FileInputStream(local));
            AnnotationConfiguration cfg = new AnnotationConfiguration();
            cfg.addFilterDefinition(new FilterDefinition("securityFilter",
                    "1=1", new HashMap()));
            cfg.configure(testCfg);
            cfg.setProperties(props);
            sessionFactory = cfg.buildSessionFactory();
        } catch (Throwable ex) {
            log.error(ex.toString());
            throw new ExceptionInInitializerError(ex);
        } 
    } 
 
    public static Session getSession() throws HibernateException {
        return sessionFactory.openSession();
    } 
7
CodeRank
This code example shows how to use the following methods:configure, buildSessionFactory
	/** 
	 * Getting a real Hibernate Session, from a memory database. 
	 */ 
	@Before 
	public void setUp() throws Exception {
		AnnotationConfiguration cfg = new AnnotationConfiguration();
		cfg.configure().setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:mydvdsDB");
		session = cfg.buildSessionFactory().openSession();
		session.beginTransaction(); 
		dao = new DefaultUserDao(session);
	} 
 
 
	/** 
	 * Undoing all changes to database 
	 * @throws Exception 
	 */ 
	@After 
	public void tearDown() throws Exception {
		if (session != null && session.getTransaction().isActive()) { 
7
CodeRank
This code example shows how to use the following methods:addAnnotatedClass, buildSessionFactory
This code example shows how to use the following methods:addAnnotatedClass, setProperty, buildSessionFactory
		 
		new ExecuteContext(getOutputDir(), file, jars) {
			 
		   protected void execute() throws Exception {
			    
			   AnnotationConfiguration configuration = new AnnotationConfiguration();
				Class puppet = getUcl().loadClass( "org.hibernate.tool.hbm2x." + className );
				configuration.addAnnotatedClass( puppet );
				 
				configuration.setProperty( "hibernate.hbm2ddl.auto", "create-drop" );
				SessionFactory sf = configuration.buildSessionFactory();
				Session s = sf.openSession();
 
				Object puppetInst = puppet.newInstance();
				puppet.getMethod( "setName", new Class[]{String.class} ).invoke( puppetInst, new Object[]{"Barbie"} );
				 
				if(className.equals("Bungalow")) { // hack to avoid not-null execption
					puppet.getMethod("setMascot", new Class[] { puppet }).invoke( puppetInst, new Object[] { puppetInst } );
				} 
				 
6
CodeRank
This code example shows how to use the following methods:addAnnotatedClass, setNamingStrategy, buildSessionFactory
        if (serviceRegistry != null) ServiceRegistryBuilder.destroy(serviceRegistry);
	} 
 
	public void testWithCustomNamingStrategy() throws Exception {
		try { 
			AnnotationConfiguration config = new AnnotationConfiguration();
			config.setNamingStrategy(new DummyNamingStrategy());
			config.addAnnotatedClass(Address.class);
			config.addAnnotatedClass(Person.class);
			config.buildSessionFactory( serviceRegistry );
		} 
		catch( Exception e ) {
			StringWriter writer = new StringWriter();
			e.printStackTrace(new PrintWriter(writer));
            log.debug(writer.toString());
			fail(e.getMessage());
		} 
	} 
 
	public void testWithEJB3NamingStrategy() throws Exception {
6
CodeRank
This code example shows how to use the following methods:
		this.applicationContext = applicationContext;
	} 
 
	@PostConstruct 
	public void create() { 
		SessionFactory original = new AnnotationConfiguration().configure().buildSessionFactory();
		factory = new SpringSessionFactory(applicationContext, original);
	} 
 
	@Override 
	public SessionFactory getInstance() {
		return factory;
	} 
 
	@PreDestroy 
	public void destroy() { 
		factory.close();
	} 
} 
6
CodeRank
This code example shows how to use the following methods:addAnnotatedClass, buildSessionFactory
		addAnnotationJars(jars);
 
		new ExecuteContext(getOutputDir(), file, jars) {
 
			protected void execute() throws Exception {
				AnnotationConfiguration configuration = new AnnotationConfiguration();
				configuration.addAnnotatedClass( getUcl().loadClass( "Project" ) );
				configuration.addAnnotatedClass( getUcl().loadClass( "Employee" ) );
			    configuration.addAnnotatedClass( getUcl().loadClass( "WorksOnContext" ) );
 
				SessionFactory sf = configuration.buildSessionFactory();
				Session s = sf.openSession();
				Query createQuery = s.createQuery("from java.lang.Object");
				createQuery.list();
				s.close();
				sf.close();
 
			} 
 
		}.run(); 
6
CodeRank
This code example shows how to use the following methods:configure, buildSessionFactory
					.setProperty("myeclipse.connection.profile", "mysql"); 
			extraProperties.setProperty("connection.driver_class", 
					"com.mysql.jdbc.Driver");*/ 
			// final Configuration cfg = new Configuration(); 
			// //这是读com/login/system/dao/impl/Users.hbm.xml 
			final AnnotationConfiguration cfg = new AnnotationConfiguration(); // 这里读com.login.system.bean.Users
			//cfg.addProperties(extraProperties); 
			cfg.configure();//("/hibernate.cfg.xml"); // 路径可以改变
			sessionFactory = cfg.buildSessionFactory();
		/*} catch (final UnsupportedEncodingException e) { 
			// 不支持字符编码。 
			e.printStackTrace(); 
		} catch (final FileNotFoundException e) { 
			// jdbc.properties文件没找到 
			e.printStackTrace(); 
		} catch (final HibernateException e) { 
			// cfg.configure("hibernate.cfg.xml");时异常 
			e.printStackTrace();*/ 
		} catch (final Exception e) {
			// 创建SessionFactory 异常 
6
CodeRank
This code example shows how to use the following methods:
	/*package*/ static SessionFactory initSessionFactory(String resource) {
		if (_factory == null) {
			try { 
				_factory = resource == null ? 
					new AnnotationConfiguration().configure().buildSessionFactory() :
					new AnnotationConfiguration().configure(resource).buildSessionFactory();
				log.debug("Hibernate configuration file loaded: "+ (resource == null ? "hibernate.cfg.xml" : resource));
			} catch (Throwable ex) {
				// Make sure you log the exception, as it might be swallowed 
				log.error("Initial SessionFactory creation failed." + ex);
				throw new ExceptionInInitializerError(ex);
			} 
		} 
		return _factory;
	} 
 
	/** 
	 * Used in {@link HibernateSessionFactoryListener} to init 
	 * Hibernate SessionFactory. 
	 */ 
6
CodeRank
See Code Examples for Hibernate ORM AnnotationConfiguration Methods: