Files
hibernate-demo/src/main/java/com/ankurm/hibernatedemo/procedure/ProcEmployee.java
T

88 lines
2.4 KiB
Java
Executable File

package com.ankurm.hibernatedemo.procedure;
import jakarta.persistence.Column;
import jakarta.persistence.ColumnResult;
import jakarta.persistence.ConstructorResult;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.NamedStoredProcedureQueries;
import jakarta.persistence.NamedStoredProcedureQuery;
import jakarta.persistence.ParameterMode;
import jakarta.persistence.SqlResultSetMapping;
import jakarta.persistence.SqlResultSetMappings;
import jakarta.persistence.StoredProcedureParameter;
import jakarta.persistence.Table;
import java.math.BigDecimal;
/**
* Entity for docs/08-stored-procedures.md (merged posts 4867 + 4881). Backed by HSQLDB 2.7.3
* real SQL/PSM stored procedures created in {@code ProcedureSchemaSupport} -- these are not
* described in prose, they are compiled and executed.
*/
@Entity
@Table(name = "PROC_EMPLOYEES")
@NamedStoredProcedureQueries({
@NamedStoredProcedureQuery(
name = "ProcEmployee.getTax",
procedureName = "GET_TAX",
parameters = {
@StoredProcedureParameter(mode = ParameterMode.IN, name = "emp_id", type = Integer.class),
@StoredProcedureParameter(mode = ParameterMode.OUT, name = "tax_amount", type = BigDecimal.class)
}
),
@NamedStoredProcedureQuery(
name = "ProcEmployee.listAll",
procedureName = "LIST_EMPLOYEES",
resultClasses = ProcEmployee.class
)
})
@SqlResultSetMappings({
@SqlResultSetMapping(
name = "EmployeeSummaryMapping",
classes = @ConstructorResult(
targetClass = EmployeeSummary.class,
columns = {
@ColumnResult(name = "ID", type = Integer.class),
@ColumnResult(name = "NAME", type = String.class)
}
)
)
})
public class ProcEmployee {
@Id
private Integer id;
private String name;
@Column(precision = 10, scale = 2)
private BigDecimal salary;
protected ProcEmployee() {
// JPA
}
public ProcEmployee(Integer id, String name, BigDecimal salary) {
this.id = id;
this.name = name;
this.salary = salary;
}
public Integer getId() {
return id;
}
public String getName() {
return name;
}
public BigDecimal getSalary() {
return salary;
}
@Override
public String toString() {
return "ProcEmployee{id=%s, name=%s, salary=%s}".formatted(id, name, salary);
}
}