Package org.hibernate

Examples of org.hibernate.SessionFactory


   * Associates the given session with the current thread of execution.
   *
   * @param session The session to bind.
   */
  public static void bind(org.hibernate.Session session) {
    SessionFactory factory = session.getSessionFactory();
    cleanupAnyOrphanedSession( factory );
    doBind( session, factory );
  }
View Full Code Here


        PersistenceUnitService persistenceUnitService = registry.getPersistenceUnitService(persistenceUnitName);
        if (persistenceUnitService != null) {
            final EntityManagerFactory entityManagerFactory = persistenceUnitService.getEntityManagerFactory();
            // TODO:  with JPA 2.1, if unwrap is added to EMF, change cast to "entityManagerFactory.unwrap(HibernateEntityManagerFactory.class)"
            HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactory;
            SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory();
            if (sessionFactory != null) {
                stats = sessionFactory.getStatistics();
                return new ManagementLookup(stats, entityManagerFactory);
            }
        }
        return null;
    }
View Full Code Here

        SFSB1 sfsb1 = lookup("SFSB1", SFSB1.class);
        sfsb1.createEmployee("Sally","1 home street", 1);

        // check if we can look up the Hibernate session factory that should of been bound because of
        // the hibernate.session_factory_name was specified in the properties (in peristence.xml above).
        SessionFactory hibernateSessionFactory = rawLookup("modelSessionFactory",SessionFactory.class);
        assertNotNull("jndi lookup of hibernate.session_factory_name should return HibernateSessionFactory", hibernateSessionFactory);

        Session session = hibernateSessionFactory.openSession();
        Employee emp = (Employee)session.get(Employee.class,1);
        assertTrue("name read from hibernate session is Sally", "Sally".equals(emp.getName()));
    }
View Full Code Here

  }

  public void index(String entity) {
    Class<?> clazz = getEntityClass( entity );

    SessionFactory factory = getSessionFactory();
    Session session = factory.openSession();
    FullTextSession fulltextSession = Search.getFullTextSession( session );
    try {
      fulltextSession.createIndexer( clazz )
          .batchSizeToLoadObjects( batchSize )
          .cacheMode( CacheMode.NORMAL )
View Full Code Here

  }

  public void optimize(String entity) {
    Class<?> clazz = getEntityClass( entity );

    SessionFactory factory = getSessionFactory();
    Session session = factory.openSession();
    FullTextSession fullTextSession = Search.getFullTextSession( session );
    fullTextSession.beginTransaction();
    fullTextSession.getSearchFactory().optimize( clazz );
    fullTextSession.getTransaction().commit();
    session.close();
View Full Code Here

  }

  public void purge(String entity) {
    Class<?> clazz = getEntityClass( entity );

    SessionFactory factory = getSessionFactory();
    Session session = factory.openSession();
    FullTextSession fullTextSession = Search.getFullTextSession( session );
    fullTextSession.beginTransaction();
    fullTextSession.purgeAll( clazz );
    fullTextSession.getTransaction().commit();
    session.close();
View Full Code Here

   * Associates the given session with the current thread of execution.
   *
   * @param session The session to bind.
   */
  public static void bind(org.hibernate.Session session) {
    SessionFactory factory = session.getSessionFactory();
    cleanupAnyOrphanedSession( factory );
    doBind( session, factory );
  }
View Full Code Here

   * @see StatisticsServiceMBean#setSessionFactoryJNDIName(java.lang.String)
   */
  public void setSessionFactoryJNDIName(String sfJNDIName) {
    this.sfJNDIName = sfJNDIName;
    try {
      final SessionFactory sessionFactory;
      final Object jndiValue = new InitialContext().lookup( sfJNDIName );
      if ( jndiValue instanceof Reference ) {
        final String uuid = (String) ( (Reference) jndiValue ).get( 0 ).getContent();
        sessionFactory = SessionFactoryRegistry.INSTANCE.getSessionFactory( uuid );
      }
View Full Code Here

    return getSessionFactory( uuid );
  }

  public SessionFactory getSessionFactory(String uuid) {
    LOG.debugf( "Lookup: uid=%s", uuid );
    final SessionFactory sessionFactory = sessionFactoryMap.get( uuid );
    if ( sessionFactory == null && LOG.isDebugEnabled() ) {
      LOG.debugf( "Not found: %s", uuid );
      LOG.debugf( sessionFactoryMap.toString() );
    }
    return sessionFactory;
View Full Code Here

        // Fetch and pre-process the Hibernate mapping descriptors.
        loadHibernateDescriptors(hbmConfig);

        // Initialize the Hibernate session factory.
        ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(hbmConfig.getProperties()).buildServiceRegistry();
        SessionFactory factory = hbmConfig.buildSessionFactory(serviceRegistry);
        hibernateSessionFactoryProvider.setSessionFactory(factory);

        // Synchronize the database schema.
        if (isEnableDatabaseAutoSynchronization() && getDatabaseAutoSynchronizer() != null) {
            getDatabaseAutoSynchronizer().synchronize(this);
View Full Code Here

TOP

Related Classes of org.hibernate.SessionFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.