Package org.springframework.orm.hibernate4

Examples of org.springframework.orm.hibernate4.HibernateTemplateTests



    @Autowired
    @Bean(name = "sessionFactory")
    public SessionFactory getSessionFactory(BasicDataSource dataSource) {
        LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource);
        sessionBuilder.addAnnotatedClasses(Book.class);
        sessionBuilder.addProperties(getHibernateProperties());
        return sessionBuilder.buildSessionFactory();
    }
View Full Code Here


    @Bean
    public SessionFactory sessionFactory() throws SQLException {

        logger.info("loading context");

        LocalSessionFactoryBuilder builder =
                new LocalSessionFactoryBuilder(dataSource());
        builder.scanPackages("org.ethereum.db")
                .addProperties(getHibernateProperties());

        return builder.buildSessionFactory();
    }
View Full Code Here

    private static final Logger logger = LoggerFactory.getLogger("general");

    @Bean
    public SessionFactory sessionFactory() throws SQLException {
        LocalSessionFactoryBuilder builder =
                new LocalSessionFactoryBuilder(dataSource());
        builder.scanPackages("org.ethereum.db")
                .addProperties(getHibernateProperties());

        return builder.buildSessionFactory();
    }
View Full Code Here

public class HibernateConfig {
 
 
  @Bean
  public SessionFactory sessionFactory() {
   return new LocalSessionFactoryBuilder(datasource())
   .addAnnotatedClasses(Account.class)
   .buildSessionFactory();
  }
View Full Code Here

      participate = true;
    }
    else {
      logger.debug("Opening Hibernate Session in OpenSessionInViewFilter");
      Session session = openSession(sessionFactory);
      TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
    }

    try {
      filterChain.doFilter(request, response);
    }

    finally {
      if (!participate) {
        SessionHolder sessionHolder =
            (SessionHolder) TransactionSynchronizationManager.unbindResource(sessionFactory);
        logger.debug("Closing Hibernate Session in OpenSessionInViewFilter");
        SessionFactoryUtils.closeSession(sessionHolder.getSession());
      }
    }
  }
View Full Code Here

      request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
    }
    else {
      logger.debug("Opening Hibernate Session in OpenSessionInViewInterceptor");
      Session session = openSession();
      TransactionSynchronizationManager.bindResource(getSessionFactory(), new SessionHolder(session));
    }
  }
View Full Code Here

      else {
        request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
      }
    }
    else {
      SessionHolder sessionHolder =
          (SessionHolder) TransactionSynchronizationManager.unbindResource(getSessionFactory());
      logger.debug("Closing Hibernate Session in OpenSessionInViewInterceptor");
      SessionFactoryUtils.closeSession(sessionHolder.getSession());
    }
  }
View Full Code Here

  private SessionFactory sessionFactory;

  @Test(expectedExceptions = IllegalTransactionStateException.class)
  public void testTransactionless() {
    Session session = sessionFactory.openSession();
    TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
    try {
      assert bookDao.all().isEmpty();
    } finally {
      TransactionSynchronizationManager.unbindResource(sessionFactory);
      SessionFactoryUtils.closeSession(session);
View Full Code Here

    session.getScope().put(PERSISTENCE_CONTEXT_ATTRIBUTE, hibernateSession);
  }

  private void bind(Session session) {
    Object sessionHolder = (hibernate3Present ?
        new org.springframework.orm.hibernate3.SessionHolder(session) : new SessionHolder(session));
    TransactionSynchronizationManager.bindResource(sessionFactory, sessionHolder);
  }
View Full Code Here

                .getResource(this.sessionFactory);

        if (value instanceof Session) {
            return (Session) value;
        } else if (value instanceof SessionHolder) {
            SessionHolder sessionHolder = (SessionHolder) value;
            Session session = sessionHolder.getSession();

            if (TransactionSynchronizationManager.isSynchronizationActive()
                    && !sessionHolder.isSynchronizedWithTransaction()) {
                TransactionSynchronizationManager
                        .registerSynchronization(new SpringSessionSynchronization(
                                sessionHolder, this.sessionFactory));
                sessionHolder.setSynchronizedWithTransaction(true);

                // Switch to FlushMode.AUTO, as we have to assume a thread-bound Session
                // with FlushMode.MANUAL, which needs to allow flushing within the transaction.
                FlushMode flushMode = session.getFlushMode();

                if (FlushMode.isManualFlushMode(flushMode)
                        && !TransactionSynchronizationManager
                                .isCurrentTransactionReadOnly()) {
                    session.setFlushMode(FlushMode.AUTO);
                    sessionHolder.setPreviousFlushMode(flushMode);
                }
            }

            return session;
        } else {
View Full Code Here

TOP

Related Classes of org.springframework.orm.hibernate4.HibernateTemplateTests

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.