Example usage for javax.persistence Query getResultList

List of usage examples for javax.persistence Query getResultList

Introduction

In this page you can find the example usage for javax.persistence Query getResultList.

Prototype

List getResultList();

Source Link

Document

Execute a SELECT query and return the query results as an untyped List.

Usage

From source file:Student.java

public static void main(String[] a) throws Exception {
        em.getTransaction().begin();//from  w w  w.  ja  v  a  2s . co  m

        Student student = new Student();
        student.setId(UUID.randomUUID().toString());
        student.setName("Joe");
        student.setDob(Calendar.getInstance().getTime());

        em.persist(student);
        em.flush();
        em.getTransaction().commit();

        Query query = em.createQuery("SELECT e FROM Student e");
        List<Student> list = (List<Student>) query.getResultList();
        System.out.println(list);

        em.close();
        emf.close();

        Helper.checkData();
    }

From source file:Student.java

public static void main(String[] a) throws Exception {
        em.getTransaction().begin();/*from www . ja  v a  2s . c o m*/

        Student student = new Student();

        student.setName("Joe");

        em.persist(student);
        em.flush();
        em.getTransaction().commit();

        Query query = em.createQuery("SELECT e FROM Student e");
        List<Student> list = (List<Student>) query.getResultList();
        System.out.println(list);

        em.close();
        emf.close();

        Helper.checkData();
    }

From source file:Student.java

public static void main(String[] a) throws Exception {
        em.getTransaction().begin();/*from   w ww. j  a va2s . c o  m*/

        Student student = new Student();
        student.setName("Joe");
        em.persist(student);

        Department dept = new Department();
        dept.setName("dept name");
        student.setDepartment(dept);

        em.flush();

        Query query = em.createQuery("SELECT e FROM Student e");
        List<Student> list = (List<Student>) query.getResultList();
        System.out.println(list);

        query = em.createQuery("SELECT d FROM Department d");
        List<Department> dList = (List<Department>) query.getResultList();
        System.out.println(dList);

        em.getTransaction().commit();
        em.close();
        emf.close();

        Helper.checkData();
    }

From source file:Project.java

public static void main(String[] a) throws Exception {
        em.getTransaction().begin();/*ww w .  j  a va  2  s.  c o  m*/

        Student student = new Student();
        student.setId(1);
        em.persist(student);

        Project dept = new Project();
        dept.setId(1);
        em.persist(dept);

        em.flush();

        em.remove(dept);

        Query query = em.createQuery("SELECT e FROM Student e");
        List<Student> list = (List<Student>) query.getResultList();
        System.out.println(list);

        query = em.createQuery("SELECT d FROM Project d");
        List<Project> dList = (List<Project>) query.getResultList();
        System.out.println(dList);

        em.getTransaction().commit();
        em.close();
        emf.close();

        Helper.checkData();
    }

From source file:Address.java

public static void main(String[] a) throws Exception {
        em.getTransaction().begin();/*from   w w w.  j av a2s . c  om*/

        Student student = new Student();
        student.setName("Joe");
        Address address = new Address();
        address.setCity("city");
        //  em.persist(address);

        student.setAddress(address);

        em.persist(student);
        em.flush();
        em.getTransaction().commit();

        Query query = em.createQuery("SELECT e FROM Student e");
        List<Student> list = (List<Student>) query.getResultList();
        System.out.println(list.get(0).getAddress());

        em.close();
        emf.close();

        Helper.checkData();
    }

From source file:Address.java

public static void main(String[] a) throws Exception {
        em.getTransaction().begin();//from   www.  j av  a  2 s .c  o  m

        Student emp = new Student();
        emp.setId(1);
        emp.setName("name");
        Address addr = new Address();
        addr.setId(1);
        addr.setStreet("street");
        addr.setCity("city");
        addr.setState("state");
        emp.setAddress(addr);
        em.persist(emp);

        Query query = em.createQuery("SELECT e FROM Student e");
        List<Student> list = (List<Student>) query.getResultList();
        System.out.println(list);

        query = em.createQuery("SELECT d FROM Address d");
        List<Address> dList = (List<Address>) query.getResultList();
        System.out.println(dList);

        em.getTransaction().commit();
        em.close();
        emf.close();

        Helper.checkData();
    }

From source file:Address.java

  public static void main(String[] a) throws Exception {
  em.getTransaction().begin();//from ww  w.j av  a  2s .c  o  m
    
    
  Student student = new Student();
  student.setName("Joe");
  Address address = new Address();
  em.persist(address);
    
  student.setAddress(address);
      
  em.persist(student);
  em.flush();
  em.getTransaction().commit();

    
  Query query = em.createQuery("SELECT e FROM Student e");
  List<Student> list = (List<Student>) query.getResultList();
  System.out.println(list);
    
    
  em.close();
  emf.close();
    
  Helper.checkData();
}

From source file:Student.java

  public static void main(String[] a) throws Exception {
  em.getTransaction().begin();//from w  ww.ja v  a  2  s  .  c om
    
    
  Student student = new Student();
  student.setName("Joe");
  em.persist(student);
    
  Student student1 = new Student();
  student1.setName("Joe");
  em.persist(student1);
    
  Department dept = new Department();
  dept.setName("dept name");
  student.setDepartment(dept);
  student1.setDepartment(dept);
    
  em.flush();
    


    
    
    
  Query query = em.createQuery("SELECT e FROM Student e");
  List<Student> list = (List<Student>) query.getResultList();
  System.out.println(list.get(0).getDepartment());
    
  query = em.createQuery("SELECT d FROM Department d");
  List<Department> dList = (List<Department>) query.getResultList();
  System.out.println(dList.get(0).getStudents());
    
  em.getTransaction().commit();
  em.close();
  emf.close();
    
  Helper.checkData();
}

From source file:Student.java

public static void main(String[] a) throws Exception {
        em.getTransaction().begin();//from   w  w w  .  j  a v a 2s  .  c  o m

        Student emp = new Student();
        emp.setId(1);
        emp.setName("name");
        Address addr = new Address();
        addr.setId(1);
        addr.setStreet("street");
        addr.setCity("city");
        addr.setState("state");
        em.persist(addr);
        emp.setAddress(addr);
        em.persist(emp);

        em.remove(emp);

        Query query = em.createQuery("SELECT e FROM Student e");
        List<Student> list = (List<Student>) query.getResultList();
        System.out.println(list);

        query = em.createQuery("SELECT d FROM Address d");
        List<Address> dList = (List<Address>) query.getResultList();
        System.out.println(dList);

        em.getTransaction().commit();
        em.close();
        emf.close();

        Helper.checkData();
    }

From source file:fr.univrouen.poste.domain.LogAuth.java

public static List<Object[]> countSuccessLogAuthsByDate() {
    String sql = "SELECT date_part('year', action_date) as year, date_part('month', action_date) as month, date_part('day', action_date) as day, count(*) as count FROM log_auth WHERE action='AUTH SUCCESS' GROUP BY year, month, day ORDER BY year, month, day";
    Query q = entityManager().createNativeQuery(sql);
    return q.getResultList();
}