Package org.hibernate

Examples of org.hibernate.Session.createQuery()


  @Test
  public void canUpdateEntityReturnedByQuery() {
    Session session = sessions.openSession();
    Transaction transaction = session.beginTransaction();

    Query query = session.createQuery( "from Helicopter h where name = 'Sergio'" );
    Helicopter helicopter = (Helicopter) query.uniqueResult();
    assertThat( helicopter ).isNotNull();
    helicopter.setName( "Leonie" );

    transaction.commit();
View Full Code Here


    transaction.commit();
    session.clear();
    transaction = session.beginTransaction();

    query = session.createQuery( "from Helicopter h where name = 'Leonie'" );
    helicopter = (Helicopter) query.uniqueResult();
    assertThat( helicopter ).isNotNull();

    transaction.commit();
    session.close();
View Full Code Here

    transaction.commit();
    session.clear();
    transaction = session.beginTransaction();

    // search and update
    StockItem loadedItem = (StockItem) session.createQuery( "from StockItem si" ).uniqueResult();
    assertNotNull( "Cannot load persisted object", loadedItem );
    loadedItem.setCount( 24 );

    transaction.commit();
    session.clear();
View Full Code Here

    LeakingMongoDBDialect.queueSize = -1;

    session = openSession();
    session.beginTransaction();
    List<Helicopter> helicopters = session.createQuery( "FROM Helicopter" ).list();
    for ( Helicopter helicopter : helicopters ) {
      session.delete( helicopter );
    }
    session.getTransaction().commit();
    session.close();
View Full Code Here

  @After
  public void clean() {
    Session session = openSession();
    session.beginTransaction();
    List<Helicopter> helicopters = session.createQuery( "FROM Helicopter" ).list();
    for ( Helicopter helicopter : helicopters ) {
      session.delete( helicopter );
    }
    session.getTransaction().commit();
    session.close();
View Full Code Here

            Map metadata = sessionFactory.getAllClassMetadata();
            for (Object o : metadata.values()) {
                EntityPersister persister = (EntityPersister) o;
                String className = persister.getEntityName();
                log.debug("Trying select * from: " + className);
                Query q = session.createQuery("from " + className + " c");
                q.iterate();
                log.debug("ok: " + className);
            }
        } finally {
            session.close();
View Full Code Here

   }

   public Object findOne(ObjectQuery q) throws Exception
   {
      Session session = openSession();
      List l = session.createQuery(q.getHibernateQuery()).list();
      if (l.size() == 0)
      {
         return null;
      }
      else if (l.size() > 1)
View Full Code Here

    }

    @Override
    public List<SystemNotification> getActiveNotifications(User user) {
        Session session = sessionManager.getSession();
        List<SystemNotification> activeNotifications = session.createQuery(
                "select sn from " + SqlSystemNotification.class.getSimpleName() + " as sn where sn.startDate <= :now and (sn.endDate is null or sn.endDate > :now)")
                .setParameter("now", new Date())
                .list();
        LOGGER.debug("returning %d active system notifications", activeNotifications.size());
        return activeNotifications;
View Full Code Here

    }

    @Override
    public List<SystemNotification> getFutureNotifications(Date maxDate, User user) {
       Session session = sessionManager.getSession();
        List<SystemNotification> futureNotifications = session.createQuery(
                "select sn from " + SqlSystemNotification.class.getSimpleName() + " as sn where sn.startDate > :now and sn.startDate < :maxDate")
                .setParameter("now", new Date())
                .setParameter("maxDate", maxDate)
                .list();
        LOGGER.debug("returning %d future system notifications", futureNotifications.size());
View Full Code Here

    @Override
    public User findByUsername(String username) {
        username = formatUsername(username);
        Session session = sessionManager.getSession();
        List<SqlUser> users = session.createQuery("select user from " + SqlUser.class.getSimpleName() + " as user where user.username=:username")
                .setParameter("username", username)
                .list();
        if (users.size() == 0) {
            return null;
        } else if (users.size() > 1) {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.