From 2c7729c7d3deed1c9cf2b9ce8a1f633f8e83e554 Mon Sep 17 00:00:00 2001 From: Kyle Doyle Date: Wed, 11 Jul 2018 15:47:56 -0400 Subject: [PATCH] BAEL-1908 Editor Feedback - simplification of Entity --- .../sqlresultsetmapping/ScheduledDay.java | 26 ++----------------- .../java-jpa/src/main/resources/database.sql | 10 +++---- .../SqlResultSetMappingUnitTest.java | 7 +++-- 3 files changed, 9 insertions(+), 34 deletions(-) diff --git a/persistence-modules/java-jpa/src/main/java/com/baeldung/sqlresultsetmapping/ScheduledDay.java b/persistence-modules/java-jpa/src/main/java/com/baeldung/sqlresultsetmapping/ScheduledDay.java index b72454c506..7e332bc67a 100644 --- a/persistence-modules/java-jpa/src/main/java/com/baeldung/sqlresultsetmapping/ScheduledDay.java +++ b/persistence-modules/java-jpa/src/main/java/com/baeldung/sqlresultsetmapping/ScheduledDay.java @@ -7,8 +7,6 @@ import javax.persistence.*; classes = { @ConstructorResult(targetClass = com.baeldung.sqlresultsetmapping.ScheduledDay.class, columns = { @ColumnResult(name = "id", type = Long.class), @ColumnResult(name = "employeeId", type = Long.class), - @ColumnResult(name = "hourIn"), - @ColumnResult(name = "hourOut"), @ColumnResult(name = "dayOfWeek") }) }), @SqlResultSetMapping(name = "FridayEmployeeResult", columns = { @ColumnResult(name = "employeeId") }), @@ -21,7 +19,7 @@ import javax.persistence.*; resultSetMapping = "FridayEmployeeResult") @NamedNativeQuery(name = "Schedules", - query = "SELECT * FROM schedule_days WHERE hourIn = 8", + query = "SELECT * FROM schedule_days WHERE employeeId = 3", resultSetMapping = "ScheduleResult") @Entity @Table(name = "SCHEDULE_DAYS") @@ -31,18 +29,14 @@ public class ScheduledDay { @GeneratedValue private Long id; private Long employeeId; - private Integer hourIn; - private Integer hourOut; private String dayOfWeek; public ScheduledDay() { } - public ScheduledDay(Long id, Long employeeId, Integer hourIn, Integer hourOut, String dayofWeek) { + public ScheduledDay(Long id, Long employeeId, String dayofWeek) { this.id = id; this.employeeId = employeeId; - this.hourIn = hourIn; - this.hourOut = hourOut; this.dayOfWeek = dayofWeek; } @@ -54,22 +48,6 @@ public class ScheduledDay { this.employeeId = employeeId; } - public Integer getHourIn() { - return hourIn; - } - - public void setHourIn(Integer hourIn) { - this.hourIn = hourIn; - } - - public Integer getHourOut() { - return hourOut; - } - - public void setHourOut(Integer hourOut) { - this.hourOut = hourOut; - } - public String getDayOfWeek() { return dayOfWeek; } diff --git a/persistence-modules/java-jpa/src/main/resources/database.sql b/persistence-modules/java-jpa/src/main/resources/database.sql index 3310c79a85..0c93dafdc7 100644 --- a/persistence-modules/java-jpa/src/main/resources/database.sql +++ b/persistence-modules/java-jpa/src/main/resources/database.sql @@ -9,11 +9,9 @@ INSERT INTO EMPLOYEE VALUES (3, 'FRANK'); CREATE TABLE SCHEDULE_DAYS (id IDENTITY, employeeId BIGINT, - hourIn int, - hourOut int, dayOfWeek VARCHAR(10)); -INSERT INTO SCHEDULE_DAYS (employeeId, hourIn, hourOut, dayOfWeek) VALUES (1, 13, 21, 'FRIDAY'); -INSERT INTO SCHEDULE_DAYS (employeeId, hourIn, hourOut, dayOfWeek) VALUES (2, 8, 4, 'SATURDAY'); -INSERT INTO SCHEDULE_DAYS (employeeId, hourIn, hourOut, dayOfWeek) VALUES (3, 8, 4, 'MONDAY'); -INSERT INTO SCHEDULE_DAYS (employeeId, hourIn, hourOut, dayOfWeek) VALUES (3, 8, 4, 'FRIDAY'); \ No newline at end of file +INSERT INTO SCHEDULE_DAYS (employeeId, dayOfWeek) VALUES (1, 'FRIDAY'); +INSERT INTO SCHEDULE_DAYS (employeeId, dayOfWeek) VALUES (2, 'SATURDAY'); +INSERT INTO SCHEDULE_DAYS (employeeId, dayOfWeek) VALUES (3, 'MONDAY'); +INSERT INTO SCHEDULE_DAYS (employeeId, dayOfWeek) VALUES (3, 'FRIDAY'); \ No newline at end of file diff --git a/persistence-modules/java-jpa/src/test/java/com/baeldung/sqlresultsetmapping/SqlResultSetMappingUnitTest.java b/persistence-modules/java-jpa/src/test/java/com/baeldung/sqlresultsetmapping/SqlResultSetMappingUnitTest.java index 7f0cbd3c1d..4e01095278 100644 --- a/persistence-modules/java-jpa/src/test/java/com/baeldung/sqlresultsetmapping/SqlResultSetMappingUnitTest.java +++ b/persistence-modules/java-jpa/src/test/java/com/baeldung/sqlresultsetmapping/SqlResultSetMappingUnitTest.java @@ -31,8 +31,8 @@ public class SqlResultSetMappingUnitTest { @Test public void whenNamedQuery_thenConstructorResult() { List scheduleDays = Collections.checkedList(em.createNamedQuery("Schedules", ScheduledDay.class).getResultList(), ScheduledDay.class); - assertEquals(3, scheduleDays.size()); - assertTrue(scheduleDays.stream().allMatch(c -> c.getHourIn().longValue() == 8)); + assertEquals(2, scheduleDays.size()); + assertTrue(scheduleDays.stream().allMatch(c -> c.getEmployeeId().longValue() == 3)); } @Test @@ -44,8 +44,7 @@ public class SqlResultSetMappingUnitTest { @Test public void whenNamedQuery_thenMultipleEntityResult() { - final Query query = em.createNativeQuery("SELECT e.id, e.name, d.id, d.employeeId, " - + " d.dayOfWeek, d.hourIn, d.hourOut " + final Query query = em.createNativeQuery("SELECT e.id, e.name, d.id, d.employeeId, d.dayOfWeek " + " FROM employee e, schedule_days d " + " WHERE e.id = d.employeeId", "EmployeeScheduleResults"); List results = query.getResultList();