package jm28;

import java.util.*;

import org.hibernate.*;
import org.hibernate.cfg.*;

public class ListaTudo {
    
    public static void main(String[] args) {

        SessionFactory sessionFactory =
            new Configuration().configure().buildSessionFactory();
            
        Session session = sessionFactory.openSession();
            
        Transaction tx = session.beginTransaction();
        
        Query query = session.createQuery(
            "select c from Cliente as c " +
            "order by c.nome");
        List<Cliente> clientes = query.list();
        Iterator<Cliente> it = clientes.iterator();    
        //Iterator it = query.iterate();    
        while (it.hasNext()) {
            Cliente cliente = it.next();
            System.out.println("[" + cliente.getId() + "] "
                + cliente.getNome()
                + " <" + cliente.getEmail() + ">");
            for(String c : cliente.getTelefones())
                System.out.println("\tTel.: " + c);
        }
        
        tx.commit();
        
        session.close();
    }
    
}
