Bael 5438 (#12176)
* [BAEL-5438] Added Criteria Queries for Employee * [BAEL-5438] Added tests and entities for named queries and criteria queries * [BAEL-5438] Removed unused sorting files * [BAEL-5438] Ignored spring context test * BAEL-5438 Indented with 4 spaces Co-authored-by: Mayank Agarwal <mayankaggarwal@zeta.tech>
This commit is contained in:
parent
66cca46069
commit
1ce8895891
|
@ -3,9 +3,11 @@ package com.baeldung.hibernate.criteria.model;
|
|||
import java.io.Serializable;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@org.hibernate.annotations.NamedQueries({ @org.hibernate.annotations.NamedQuery(name = "Employee_findByEmployeeId", query = "from Employee where id = :employeeId"),
|
||||
@org.hibernate.annotations.NamedQueries({
|
||||
@org.hibernate.annotations.NamedQuery(name = "Employee_findByEmployeeId", query = "from Employee where id = :employeeId"),
|
||||
@org.hibernate.annotations.NamedQuery(name = "Employee_findAllByEmployeeSalary", query = "from Employee where salary = :employeeSalary")})
|
||||
@org.hibernate.annotations.NamedNativeQueries({ @org.hibernate.annotations.NamedNativeQuery(name = "Employee_FindByEmployeeId", query = "select * from employee emp where employeeId=:employeeId", resultClass = Employee.class)})
|
||||
@org.hibernate.annotations.NamedNativeQueries({
|
||||
@org.hibernate.annotations.NamedNativeQuery(name = "Employee_FindByEmployeeId", query = "select * from employee emp where employeeId=:employeeId", resultClass = Employee.class)})
|
||||
@Entity
|
||||
public class Employee implements Serializable {
|
||||
|
||||
|
@ -35,18 +37,23 @@ public class Employee implements Serializable {
|
|||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj)
|
||||
if (this == obj) {
|
||||
return true;
|
||||
if (obj == null)
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final Employee other = (Employee) obj;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
if (other.id != null) {
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
}
|
||||
} else if (!id.equals(other.id)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,5 +41,4 @@ public class EmployeeCriteriaQueries {
|
|||
session.close();
|
||||
return employeeWithGreaterSalary;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,8 @@ public interface EmployeeRepository extends JpaRepository<Employee, Integer> {
|
|||
|
||||
@Query(
|
||||
value = "SELECT * FROM Employee e WHERE e.salary = ?1",
|
||||
nativeQuery = true)
|
||||
nativeQuery = true
|
||||
)
|
||||
Employee findUserBySalaryNative(Long salary);
|
||||
|
||||
@Query("SELECT e FROM Employee e WHERE e.name = :name and e.salary = :salary")
|
||||
|
@ -28,8 +29,10 @@ public interface EmployeeRepository extends JpaRepository<Employee, Integer> {
|
|||
@Param("name") String employeeName,
|
||||
@Param("salary") Long employeeSalary);
|
||||
|
||||
@Query(value = "SELECT * FROM Employee e WHERE e.name = :name and e.salary = :salary",
|
||||
nativeQuery = true)
|
||||
@Query(
|
||||
value = "SELECT * FROM Employee e WHERE e.name = :name and e.salary = :salary",
|
||||
nativeQuery = true
|
||||
)
|
||||
Employee findUserByNameAndSalaryNamedParamsNative(
|
||||
@Param("name") String employeeName,
|
||||
@Param("salary") Long employeeSalary);
|
||||
|
|
Loading…
Reference in New Issue