|
| 1 | +package com.baeldung.sqlresultsetmapping; |
| 2 | + |
| 3 | +import javax.persistence.*; |
| 4 | + |
| 5 | +@SqlResultSetMappings(value = { |
| 6 | + @SqlResultSetMapping(name = "ScheduleResult", |
| 7 | + classes = { @ConstructorResult(targetClass = com.baeldung.sqlresultsetmapping.ScheduledDay.class, |
| 8 | + columns = { @ColumnResult(name = "id", type = Long.class), |
| 9 | + @ColumnResult(name = "employeeId", type = Long.class), |
| 10 | + @ColumnResult(name = "hourIn"), |
| 11 | + @ColumnResult(name = "hourOut"), |
| 12 | + @ColumnResult(name = "dayOfWeek") }) }), |
| 13 | + @SqlResultSetMapping(name = "FridayEmployeeResult", |
| 14 | + columns = { @ColumnResult(name = "employeeId") }), |
| 15 | + @SqlResultSetMapping(name = "EmployeeScheduleResults", |
| 16 | + entities = { @EntityResult(entityClass = com.baeldung.sqlresultsetmapping.Employee.class), |
| 17 | + @EntityResult(entityClass = com.baeldung.sqlresultsetmapping.ScheduledDay.class) |
| 18 | + }) }) |
| 19 | +@NamedNativeQuery(name = "FridayEmployees", |
| 20 | + query = "SELECT employeeId FROM schedule_days WHERE dayOfWeek = 'FRIDAY'", |
| 21 | + resultSetMapping = "FridayEmployeeResult") |
| 22 | + |
| 23 | +@NamedNativeQuery(name = "Schedules", |
| 24 | + query = "SELECT * FROM schedule_days WHERE hourIn = 8", |
| 25 | + resultSetMapping = "ScheduleResult") |
| 26 | +@Entity |
| 27 | +@Table(name = "SCHEDULE_DAYS") |
| 28 | +public class ScheduledDay { |
| 29 | + |
| 30 | + @Id |
| 31 | + @GeneratedValue |
| 32 | + private Long id; |
| 33 | + private Long employeeId; |
| 34 | + private Integer hourIn; |
| 35 | + private Integer hourOut; |
| 36 | + private String dayOfWeek; |
| 37 | + |
| 38 | + public ScheduledDay() { |
| 39 | + } |
| 40 | + |
| 41 | + public ScheduledDay(Long id, Long employeeId, Integer hourIn, Integer hourOut, String dayofWeek) { |
| 42 | + this.id = id; |
| 43 | + this.employeeId = employeeId; |
| 44 | + this.hourIn = hourIn; |
| 45 | + this.hourOut = hourOut; |
| 46 | + this.dayOfWeek = dayofWeek; |
| 47 | + } |
| 48 | + |
| 49 | + public Long getEmployeeId() { |
| 50 | + return employeeId; |
| 51 | + } |
| 52 | + |
| 53 | + public void setEmployeeId(Long employeeId) { |
| 54 | + this.employeeId = employeeId; |
| 55 | + } |
| 56 | + |
| 57 | + public Integer getHourIn() { |
| 58 | + return hourIn; |
| 59 | + } |
| 60 | + |
| 61 | + public void setHourIn(Integer hourIn) { |
| 62 | + this.hourIn = hourIn; |
| 63 | + } |
| 64 | + |
| 65 | + public Integer getHourOut() { |
| 66 | + return hourOut; |
| 67 | + } |
| 68 | + |
| 69 | + public void setHourOut(Integer hourOut) { |
| 70 | + this.hourOut = hourOut; |
| 71 | + } |
| 72 | + |
| 73 | + public String getDayOfWeek() { |
| 74 | + return dayOfWeek; |
| 75 | + } |
| 76 | + |
| 77 | + public void setDayOfWeek(String dayOfWeek) { |
| 78 | + this.dayOfWeek = dayOfWeek; |
| 79 | + } |
| 80 | +} |
0 commit comments