hibernate中Query和Criteria的用法

        //Scenario 1: query all users with HQL
        Query query = session.createQuery("select u from Users as u");
        List users = query.list();

        
        //Scenarion 2: conditional query with HQL
        /*
        Query query = session.createQuery("select u from Users as u where u.uid = ? "); 
        query.setInteger(0, 1);
        List users = query.list(); 
        */
        
        //Scenario 3: query all users with criteria API
        /*
        Criteria criteria = session.createCriteria(Users.class);
        List users = criteria.list();
        */
        
        //Scenario 4: conditional query with criteria API
        /*
        Criteria criteria = session.createCriteria(Users.class);
        criteria.add(Expression.eq("username", "useraaa"));
        List users = criteria.list();
        */

你可能感兴趣的:(Hibernate,idea)