0% found this document useful (0 votes)
7 views2 pages

nativeQuery

Uploaded by

Mohamamd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

nativeQuery

Uploaded by

Mohamamd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

@Entity(name="EmployeeEntity")

@Table (name="employee")

@NamedNativeQueries({

@NamedNativeQuery(

name = "getAllEmployees",

query = "SELECT id, firstName, lastName, email, department.id, department.name " +

"FROM employee, department",

resultClass=EmployeeEntity.class

),

@NamedNativeQuery(

name = "getAllEmployeesByDeptId",

query = "SELECT id, firstName, lastName, email, department.id, department.name " +

"FROM employee, department " +

"WHERE department.id = ?",

resultClass=EmployeeEntity.class

})

public class EmployeeEntity implements Serializable

//more code

@Override

public List<EmployeeEntity> getAllEmployees() {

List<EmployeeEntity> employees = manager.createNamedQuery("getAllEmployees",


EmployeeEntity.class)
.getResultList();

return employees;

@Override

public List<EmployeeEntity> getAllEmployeesByDeptId(Integer id) {

List<EmployeeEntity> employees = manager.createNamedQuery("getAllEmployeesByDeptId",


EmployeeEntity.class)

.setParameter(1, id)

.getResultList();

return employees;

You might also like