Get all records from table - EclipseLink

Maximus Decimus

I've been trying to get all rows from table in EclipseLink.

I created my entities from db with the JPA tools. This is the result:

@Entity
@Table(name="employee", schema="hr")
@NamedQuery(name="Employee.findAll", query="SELECT e FROM Employee e")
public class Employee implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Integer id;

    private String name;

    public Employee() {
    }

    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

}

I found many pages where people create Query object to get all the records but they define again the "select" query like this.

Query q = em.createQuery("select e from Employee e");

But doing a research, finally I found something like this:

   public List<Employee> getEmployees() {
        EntityManagerFactory factory = Persistence.createEntityManagerFactory("ResourcesService");
        EntityManager em = factory.createEntityManager();
        Query q = em.createQuery("from Employee e", Employee.class);
        return q.getResultList();
   }

Is there a even more simplified way to query this, just using the class name? Because the mapped entity already contains the select query.

I mean instead of doing this

   Query q = em.createQuery("from Employee e", Employee.class);

To do something like this fictional example:

   Query q = em.createQuery(Employee.class);
K.Nicholas

Why not use the named query you have defined?

em.createNamedQuery("Employee.findAll").getResultList();

You could name it "Employee.class" ... :-)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get all records from azure table storage

From Dev

Get all records from another table with pivot

From Dev

Get Records from Referenced Table "Minus" All The Records referenced from the Referencing Table

From Dev

How to get all records from one table and only records from joined table with criteria

From Dev

sql get all the records from table with some conditions

From Dev

how to get all the records from MySQL table in php web services

From Dev

How can I get all records from one table, even if there are no corresponding records in the JOINed table?

From Dev

get records without records from another table

From Dev

Get records from third table

From Dev

How to get 2 id from tow column and get all records from another table

From Dev

How to get all records from one table and save it on another table by c# in winforms?

From Dev

How to get all records from one table between dates of column in another table

From Dev

Get all records if table valued parameter is null

From Dev

Get all records in table without field

From Dev

Retriving all records from left table and matching records from right

From Dev

Not getting all records from Table A in left join

From Dev

Getting all records from database to Vaadin Table

From Dev

How to display all records from a table with RedBeanPHP?

From Dev

Delete all records from table that starts with <

From Dev

Get all records from Model that do NOT have an entry in pivot table Laravel 5

From Dev

Access - Join two tables on two fields, get all records from table A

From Dev

All records being deleted when deleting records from a temp table

From Dev

Get all Rails records from an array of IDs

From Dev

How to get all records from set in aerospike?

From Dev

Get All Records of Monday from Database

From Dev

to get unique records from table after join

From Dev

Get the latest date of records from a table, SQL

From Dev

Get the repeating records from table only once?

From Dev

Get total records of children from connected table

Related Related

  1. 1

    Get all records from azure table storage

  2. 2

    Get all records from another table with pivot

  3. 3

    Get Records from Referenced Table "Minus" All The Records referenced from the Referencing Table

  4. 4

    How to get all records from one table and only records from joined table with criteria

  5. 5

    sql get all the records from table with some conditions

  6. 6

    how to get all the records from MySQL table in php web services

  7. 7

    How can I get all records from one table, even if there are no corresponding records in the JOINed table?

  8. 8

    get records without records from another table

  9. 9

    Get records from third table

  10. 10

    How to get 2 id from tow column and get all records from another table

  11. 11

    How to get all records from one table and save it on another table by c# in winforms?

  12. 12

    How to get all records from one table between dates of column in another table

  13. 13

    Get all records if table valued parameter is null

  14. 14

    Get all records in table without field

  15. 15

    Retriving all records from left table and matching records from right

  16. 16

    Not getting all records from Table A in left join

  17. 17

    Getting all records from database to Vaadin Table

  18. 18

    How to display all records from a table with RedBeanPHP?

  19. 19

    Delete all records from table that starts with <

  20. 20

    Get all records from Model that do NOT have an entry in pivot table Laravel 5

  21. 21

    Access - Join two tables on two fields, get all records from table A

  22. 22

    All records being deleted when deleting records from a temp table

  23. 23

    Get all Rails records from an array of IDs

  24. 24

    How to get all records from set in aerospike?

  25. 25

    Get All Records of Monday from Database

  26. 26

    to get unique records from table after join

  27. 27

    Get the latest date of records from a table, SQL

  28. 28

    Get the repeating records from table only once?

  29. 29

    Get total records of children from connected table

HotTag

Archive