Add Hibernate 7 batches 2-6, batch 7, and batch 8: mapping styles, JPA annotations, natural IDs, @Immutable, stored procedures, in-memory test databases, JNDI mocking, proxies, associations, temporal mapping, named queries, HQL, Criteria API, EntityManager bootstrapping, Ehcache 3 L2 cache configuration, HikariCP connection pooling, Hibernate Validator CDI integration, aggregate functions, sorting, pagination, interceptors, and Hibernate Search 8 (Hibernate 7.4.5.Final + Spring Boot 4.1.1 + JDK 25)
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package com.ankurm.hibernatedemo.namedquery;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.NamedQueries;
|
||||
import jakarta.persistence.NamedQuery;
|
||||
import jakarta.persistence.NamedNativeQueries;
|
||||
import jakarta.persistence.NamedNativeQuery;
|
||||
import jakarta.persistence.SqlResultSetMapping;
|
||||
import jakarta.persistence.ConstructorResult;
|
||||
import jakarta.persistence.ColumnResult;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
/**
|
||||
* Backs ankurm.com post 4877. Docs: 14-named-queries.md.
|
||||
*
|
||||
* <p>{@code Employee.findByName} is a valid JPA {@code @NamedQuery}, {@code Employee.byNativeDto}
|
||||
* is a {@code @NamedNativeQuery} + {@code @SqlResultSetMapping} into {@link EmployeeDto} via
|
||||
* {@code @ConstructorResult}.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "nq_employee")
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "Employee.findByName", query = "SELECT e FROM NqEmployee e WHERE e.firstName = :name"),
|
||||
@NamedQuery(name = "Employee.findAllActive", query = "SELECT e FROM NqEmployee e WHERE e.status = 'ACTIVE' ORDER BY e.id DESC")
|
||||
})
|
||||
@NamedNativeQueries({
|
||||
@NamedNativeQuery(
|
||||
name = "Employee.byNativeDto",
|
||||
query = "SELECT id, first_name AS firstName FROM nq_employee WHERE status = :status",
|
||||
resultSetMapping = "EmployeeDtoMapping")
|
||||
})
|
||||
@SqlResultSetMapping(
|
||||
name = "EmployeeDtoMapping",
|
||||
classes = @ConstructorResult(
|
||||
targetClass = EmployeeDto.class,
|
||||
columns = {
|
||||
@ColumnResult(name = "id", type = Long.class),
|
||||
@ColumnResult(name = "firstName", type = String.class)
|
||||
}))
|
||||
public class NqEmployee {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private String firstName;
|
||||
|
||||
private String status;
|
||||
|
||||
protected NqEmployee() {
|
||||
}
|
||||
|
||||
public NqEmployee(String firstName, String status) {
|
||||
this.firstName = firstName;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user