из базы данных поле сотрудника заполнено корректно, я пробовал получить данные из базы как с помощью метода findAll(), который предоставляет нам JPA-интерфейс, так и с помощью собственный метод
public interface EmployeeRepository extends JpaRepository {
///**
//* Searching employee by id
//*
//* @param id of the searched employee
//* @return the searched employee
//*/
//@Query("select e from Employee e where e.id = :id")
//Employee getEmployeeById(Long id);
@Query("SELECT e FROM Employee e JOIN FETCH e.workedShift")
List findAllWithShifts();
/**
* Searching employee by full name
*
* @param fullName of the searched employee
* @return the searched employee
*/
@Query("SELECT e FROM Employee e WHERE LOWER(CONCAT(e.firstName, ' ', e.lastName)) = lower(:fullName)")
Employee getEmployeeByFullName(String fullName);
/**
* Searching employee by PESEL
*
* @param pesel of the searched employee
* @return the searched employee
*/
@Query("SELECT e FROM Employee e WHERE e.PESEL = :pesel")
Employee getEmployeeByPESEL(String pesel);
}
. Вот собственно мой класс, на котором я непосредственно занимаюсь задачей
@Component
@AllArgsConstructor
public class BootStrap implements CommandLineRunner {
EmployeeRepository employeeRepository;
ShiftRepository shiftRepository;
EmployeeService employeeService;
ShiftServiceImpl shiftService;
@Override
public void run(String... args){
Employee employee = Employee.builder()
.firstName("Adam")
.lastName("Kowalski")
.PESEL("03947283728")
.rate(23.5)
.build();
Employee savedEmployee = employeeRepository.save(employee);
Stream randomShifts = Stream.generate(() -> {
return Shift.builder()
.station("Station " + (new Random().nextInt(10) + 1))
.date(LocalDate.of(2024,5,5))
.startTime("10:00")
.endTime("20:00")
.actualStartTime("10:00")
.actualEndTime("20:00")
.employee(savedEmployee)
.build();
}).limit(5);
shiftRepository.saveAll(randomShifts.collect(Collectors.toUnmodifiableSet()));
System.out.println("\n after save all\n");
System.out.println("\n All employees "+ employeeService.getAllEmployees());
System.out.println("\nsalary= "+employeeService.getMonthSalary(1L,5));
System.out.println("\ntax= "+employeeService.getMonthTax(1L,5));
System.out.println("\nRevenue= "+employeeService.getMonthRevenue(1L,5));
//employeeRepository.findAll().forEach(publisher -> System.out.println("\n"+publisher+" have "+publisher.getWorkedShift()));
employeeRepository.findAll().forEach(publisher -> System.out.println("\n"+publisher+" have "+publisher.getWorkedShift()));
shiftRepository.findAll().forEach(book -> System.out.println("\n"+book+ " have "+book.getEmployee()));
System.out.println();
System.out.println("\n all shift by employee 1"+shiftService.getAllShiftByEmployee(1L));
System.out.println();
System.out.println("\n employee with pesel"+employeeService.getEmployeeByPESEL("03947283728"));
}
}
здесь я сохраняю данные в базу данных, а затем фактически извлекаю их, также наблюдаю проблему, когда манипулирую данными через контроллеры.
так выглядит база данных после заполнения его данными
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.2.4)
2024-05-11T01:32:13.941+02:00 INFO 10492 --- [LearnTest] [ main] i.d.learntest.LearnTestApplication : Starting LearnTestApplication using Java 21.0.2 with PID 10492 (C:\Users\SystemX\IdeaProjects\LearnTest\target\classes started by SystemX in C:\Users\SystemX\IdeaProjects\LearnTest)
2024-05-11T01:32:13.943+02:00 INFO 10492 --- [LearnTest] [ main] i.d.learntest.LearnTestApplication : No active profile set, falling back to 1 default profile: "default"
2024-05-11T01:32:14.486+02:00 INFO 10492 --- [LearnTest] [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2024-05-11T01:32:14.517+02:00 INFO 10492 --- [LearnTest] [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 26 ms. Found 2 JPA repository interfaces.
2024-05-11T01:32:14.803+02:00 INFO 10492 --- [LearnTest] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http)
2024-05-11T01:32:14.811+02:00 INFO 10492 --- [LearnTest] [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2024-05-11T01:32:14.811+02:00 INFO 10492 --- [LearnTest] [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.19]
2024-05-11T01:32:14.851+02:00 INFO 10492 --- [LearnTest] [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2024-05-11T01:32:14.851+02:00 INFO 10492 --- [LearnTest] [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 705 ms
2024-05-11T01:32:14.874+02:00 INFO 10492 --- [LearnTest] [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2024-05-11T01:32:15.004+02:00 INFO 10492 --- [LearnTest] [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection conn0: url=jdbc:h2:mem:e7e97f48-70df-4ac1-8cb7-88dec0dd2f58 user=SA
2024-05-11T01:32:15.005+02:00 INFO 10492 --- [LearnTest] [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2024-05-11T01:32:15.012+02:00 INFO 10492 --- [LearnTest] [ main] o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:e7e97f48-70df-4ac1-8cb7-88dec0dd2f58'
2024-05-11T01:32:15.096+02:00 INFO 10492 --- [LearnTest] [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2024-05-11T01:32:15.126+02:00 INFO 10492 --- [LearnTest] [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.4.4.Final
2024-05-11T01:32:15.145+02:00 INFO 10492 --- [LearnTest] [ main] o.h.c.internal.RegionFactoryInitiator : HHH000026: Second-level cache disabled
2024-05-11T01:32:15.284+02:00 INFO 10492 --- [LearnTest] [ main] o.s.o.j.p.SpringPersistenceUnitInfo : No LoadTimeWeaver setup: ignoring JPA class transformer
2024-05-11T01:32:15.897+02:00 INFO 10492 --- [LearnTest] [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
Hibernate: drop table if exists employee cascade
Hibernate: drop table if exists shift cascade
Hibernate: create table employee (date_of_birthday date, rate float(53), type_of_contract tinyint check (type_of_contract between 0 and 3), id bigint generated by default as identity, first_name varchar(255), last_name varchar(255), pesel varchar(255), specialization varchar(255), zusindex varchar(255), primary key (id))
Hibernate: create table shift (date date, employee_id bigint, id bigint generated by default as identity, actual_end_time varchar(255), actual_start_time varchar(255), end_time varchar(255), start_time varchar(255), station varchar(255), primary key (id))
Hibernate: alter table if exists shift add constraint FKg9ycreft1sv2jjvkno3dn3fqy foreign key (employee_id) references employee
2024-05-11T01:32:15.928+02:00 INFO 10492 --- [LearnTest] [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2024-05-11T01:32:16.066+02:00 INFO 10492 --- [LearnTest] [ main] o.s.d.j.r.query.QueryEnhancerFactory : Hibernate is in classpath; If applicable, HQL parser will be used.
2024-05-11T01:32:16.470+02:00 WARN 10492 --- [LearnTest] [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2024-05-11T01:32:16.677+02:00 WARN 10492 --- [LearnTest] [ main] .b.a.g.t.GroovyTemplateAutoConfiguration : Cannot find template location: classpath:/templates/ (please add some templates, check your Groovy configuration, or set spring.groovy.template.check-template-location=false)
2024-05-11T01:32:16.836+02:00 INFO 10492 --- [LearnTest] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path ''
2024-05-11T01:32:16.841+02:00 INFO 10492 --- [LearnTest] [ main] i.d.learntest.LearnTestApplication : Started LearnTestApplication in 3.117 seconds (process running for 3.473)
Hibernate: insert into employee (pesel,zusindex,date_of_birthday,first_name,last_name,rate,specialization,type_of_contract,id) values (?,?,?,?,?,?,?,?,default)
Hibernate: insert into shift (actual_end_time,actual_start_time,date,employee_id,end_time,start_time,station,id) values (?,?,?,?,?,?,?,default)
Hibernate: insert into shift (actual_end_time,actual_start_time,date,employee_id,end_time,start_time,station,id) values (?,?,?,?,?,?,?,default)
Hibernate: insert into shift (actual_end_time,actual_start_time,date,employee_id,end_time,start_time,station,id) values (?,?,?,?,?,?,?,default)
Hibernate: insert into shift (actual_end_time,actual_start_time,date,employee_id,end_time,start_time,station,id) values (?,?,?,?,?,?,?,default)
after save all
Hibernate: select e1_0.id,e1_0.pesel,e1_0.zusindex,e1_0.date_of_birthday,e1_0.first_name,e1_0.last_name,e1_0.rate,e1_0.specialization,e1_0.type_of_contract from employee e1_0
Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=?
Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=?
All employees [Employee{id=1, firstName='Adam', lastName='Kowalski', rate=23.5, typeOfContract=null, specialization='null', dateOfBirthday=null, PESEL='03947283728', ZUSindex='null'}]
Hibernate: select e1_0.id,e1_0.pesel,e1_0.zusindex,e1_0.date_of_birthday,e1_0.first_name,e1_0.last_name,e1_0.rate,e1_0.specialization,e1_0.type_of_contract,ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from employee e1_0 left join shift ws1_0 on e1_0.id=ws1_0.employee_id where e1_0.id=?
Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=?
salary= 0.0
Hibernate: select e1_0.id,e1_0.pesel,e1_0.zusindex,e1_0.date_of_birthday,e1_0.first_name,e1_0.last_name,e1_0.rate,e1_0.specialization,e1_0.type_of_contract,ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from employee e1_0 left join shift ws1_0 on e1_0.id=ws1_0.employee_id where e1_0.id=?
Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=?
tax= {social security contributions=0.0, advance income tax=-30.0, Health insurance contribution=0.0, PPK=0.0, Tax=-330.0}
Hibernate: select e1_0.id,e1_0.pesel,e1_0.zusindex,e1_0.date_of_birthday,e1_0.first_name,e1_0.last_name,e1_0.rate,e1_0.specialization,e1_0.type_of_contract,ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from employee e1_0 left join shift ws1_0 on e1_0.id=ws1_0.employee_id where e1_0.id=?
Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=?
Revenue= 0.0
Hibernate: select e1_0.id,e1_0.pesel,e1_0.zusindex,e1_0.date_of_birthday,e1_0.first_name,e1_0.last_name,e1_0.rate,e1_0.specialization,e1_0.type_of_contract from employee e1_0
Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=?
Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=?
Employee{id=1, firstName='Adam', lastName='Kowalski', rate=23.5, typeOfContract=null, specialization='null', dateOfBirthday=null, PESEL='03947283728', ZUSindex='null'} have []
Hibernate: select s1_0.id,s1_0.actual_end_time,s1_0.actual_start_time,s1_0.date,s1_0.employee_id,s1_0.end_time,s1_0.start_time,s1_0.station from shift s1_0
Hibernate: select e1_0.id,e1_0.pesel,e1_0.zusindex,e1_0.date_of_birthday,e1_0.first_name,e1_0.last_name,e1_0.rate,e1_0.specialization,e1_0.type_of_contract,ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from employee e1_0 left join shift ws1_0 on e1_0.id=ws1_0.employee_id where e1_0.id=?
Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=?
Shift{id=1, station='Station 5', date=2024-05-05, startTime='10:00', endTime='20:00', actualStartTime='10:00', actualEndTime='20:00', employee=Employee{id=1, firstName='Adam', lastName='Kowalski', rate=23.5, typeOfContract=null, specialization='null', dateOfBirthday=null, PESEL='03947283728', ZUSindex='null'}} have Employee{id=1, firstName='Adam', lastName='Kowalski', rate=23.5, typeOfContract=null, specialization='null', dateOfBirthday=null, PESEL='03947283728', ZUSindex='null'}
Shift{id=2, station='Station 6', date=2024-05-05, startTime='10:00', endTime='20:00', actualStartTime='10:00', actualEndTime='20:00', employee=Employee{id=1, firstName='Adam', lastName='Kowalski', rate=23.5, typeOfContract=null, specialization='null', dateOfBirthday=null, PESEL='03947283728', ZUSindex='null'}} have Employee{id=1, firstName='Adam', lastName='Kowalski', rate=23.5, typeOfContract=null, specialization='null', dateOfBirthday=null, PESEL='03947283728', ZUSindex='null'}
Shift{id=3, station='Station 8', date=2024-05-05, startTime='10:00', endTime='20:00', actualStartTime='10:00', actualEndTime='20:00', employee=Employee{id=1, firstName='Adam', lastName='Kowalski', rate=23.5, typeOfContract=null, specialization='null', dateOfBirthday=null, PESEL='03947283728', ZUSindex='null'}} have Employee{id=1, firstName='Adam', lastName='Kowalski', rate=23.5, typeOfContract=null, specialization='null', dateOfBirthday=null, PESEL='03947283728', ZUSindex='null'}
Shift{id=4, station='Station 2', date=2024-05-05, startTime='10:00', endTime='20:00', actualStartTime='10:00', actualEndTime='20:00', employee=Employee{id=1, firstName='Adam', lastName='Kowalski', rate=23.5, typeOfContract=null, specialization='null', dateOfBirthday=null, PESEL='03947283728', ZUSindex='null'}} have Employee{id=1, firstName='Adam', lastName='Kowalski', rate=23.5, typeOfContract=null, specialization='null', dateOfBirthday=null, PESEL='03947283728', ZUSindex='null'}
Hibernate: select count(*) from employee e1_0 where e1_0.id=?
Hibernate: select s1_0.id,s1_0.actual_end_time,s1_0.actual_start_time,s1_0.date,s1_0.employee_id,s1_0.end_time,s1_0.start_time,s1_0.station from shift s1_0 where s1_0.employee_id=?
Hibernate: select e1_0.id,e1_0.pesel,e1_0.zusindex,e1_0.date_of_birthday,e1_0.first_name,e1_0.last_name,e1_0.rate,e1_0.specialization,e1_0.type_of_contract,ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from employee e1_0 left join shift ws1_0 on e1_0.id=ws1_0.employee_id where e1_0.id=?
Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=?
all shift by employee 1[Shift{id=1, station='Station 5', date=2024-05-05, startTime='10:00', endTime='20:00', actualStartTime='10:00', actualEndTime='20:00', employee=Employee{id=1, firstName='Adam', lastName='Kowalski', rate=23.5, typeOfContract=null, specialization='null', dateOfBirthday=null, PESEL='03947283728', ZUSindex='null'}}, Shift{id=2, station='Station 6', date=2024-05-05, startTime='10:00', endTime='20:00', actualStartTime='10:00', actualEndTime='20:00', employee=Employee{id=1, firstName='Adam', lastName='Kowalski', rate=23.5, typeOfContract=null, specialization='null', dateOfBirthday=null, PESEL='03947283728', ZUSindex='null'}}, Shift{id=3, station='Station 8', date=2024-05-05, startTime='10:00', endTime='20:00', actualStartTime='10:00', actualEndTime='20:00', employee=Employee{id=1, firstName='Adam', lastName='Kowalski', rate=23.5, typeOfContract=null, specialization='null', dateOfBirthday=null, PESEL='03947283728', ZUSindex='null'}}, Shift{id=4, station='Station 2', date=2024-05-05, startTime='10:00', endTime='20:00', actualStartTime='10:00', actualEndTime='20:00', employee=Employee{id=1, firstName='Adam', lastName='Kowalski', rate=23.5, typeOfContract=null, specialization='null', dateOfBirthday=null, PESEL='03947283728', ZUSindex='null'}}]
Hibernate: select e1_0.id,e1_0.pesel,e1_0.zusindex,e1_0.date_of_birthday,e1_0.first_name,e1_0.last_name,e1_0.rate,e1_0.specialization,e1_0.type_of_contract from employee e1_0 where e1_0.pesel=?
Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=?
Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=?
employee with peselEmployee{id=1, firstName='Adam', lastName='Kowalski', rate=23.5, typeOfContract=null, specialization='null', dateOfBirthday=null, PESEL='03947283728', ZUSindex='null'}
Я использую базу данных h2
Пытался изменить порядок добавления объектов в базу, проверил два кода (рабочий и неработающий), извлекал объекты разными способами, удалял и добавлял аннотации к классам сущностей
Ожидаю, что при получении сотрудника из базы поле "Рабочие смены" заполнится соответствующими значениями
Пытаюсь сделать простую программу для построения графика работы, но не могу правильно получить данные. когда я пытаюсь нанять сотрудника [code]@Entity @Data @Builder @AllArgsConstructor @NoArgsConstructor public class Employee {
long totalMinutes = duration.toMinutes(); int hours = (int) (totalMinutes / 60); int minutes = (int) (totalMinutes % 60);
return new HoursClass(hours, minutes); }
@Override public int compareTo(Shift o) { return 0; }
@Override public String toString() { return "Shift{" + "id=" + id + ", station='" + station + '\'' + ", date=" + date + ", startTime='" + startTime + '\'' + ", endTime='" + endTime + '\'' + ", actualStartTime='" + actualStartTime + '\'' + ", actualEndTime='" + actualEndTime + '\'' + ", employee=" + employee + '}'; } } [/code] из базы данных поле сотрудника заполнено корректно, я пробовал получить данные из базы как с помощью метода findAll(), который предоставляет нам JPA-интерфейс, так и с помощью собственный метод [code]public interface EmployeeRepository extends JpaRepository {
///** //* Searching employee by id //* //* @param id of the searched employee //* @return the searched employee //*/ //@Query("select e from Employee e where e.id = :id") //Employee getEmployeeById(Long id); @Query("SELECT e FROM Employee e JOIN FETCH e.workedShift") List findAllWithShifts(); /** * Searching employee by full name * * @param fullName of the searched employee * @return the searched employee */ @Query("SELECT e FROM Employee e WHERE LOWER(CONCAT(e.firstName, ' ', e.lastName)) = lower(:fullName)") Employee getEmployeeByFullName(String fullName); /** * Searching employee by PESEL * * @param pesel of the searched employee * @return the searched employee */ @Query("SELECT e FROM Employee e WHERE e.PESEL = :pesel") Employee getEmployeeByPESEL(String pesel); }
. Вот собственно мой класс, на котором я непосредственно занимаюсь задачей @Component @AllArgsConstructor public class BootStrap implements CommandLineRunner {
//employeeRepository.findAll().forEach(publisher -> System.out.println("\n"+publisher+" have "+publisher.getWorkedShift())); employeeRepository.findAll().forEach(publisher -> System.out.println("\n"+publisher+" have "+publisher.getWorkedShift())); shiftRepository.findAll().forEach(book -> System.out.println("\n"+book+ " have "+book.getEmployee()));
System.out.println(); System.out.println("\n all shift by employee 1"+shiftService.getAllShiftByEmployee(1L)); System.out.println(); System.out.println("\n employee with pesel"+employeeService.getEmployeeByPESEL("03947283728")); } } [/code] здесь я сохраняю данные в базу данных, а затем фактически извлекаю их, также наблюдаю проблему, когда манипулирую данными через контроллеры. так выглядит база данных после заполнения его данными [code][shift table](https://i.sstatic.net/26KW7O4M.png) [employee table](https://i.sstatic.net/mhdSRqDs.png) [/code] , и это журнал, который показывает консоль сразу после запуска класса [code] . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v3.2.4)
2024-05-11T01:32:13.941+02:00 INFO 10492 --- [LearnTest] [ main] i.d.learntest.LearnTestApplication : Starting LearnTestApplication using Java 21.0.2 with PID 10492 (C:\Users\SystemX\IdeaProjects\LearnTest\target\classes started by SystemX in C:\Users\SystemX\IdeaProjects\LearnTest) 2024-05-11T01:32:13.943+02:00 INFO 10492 --- [LearnTest] [ main] i.d.learntest.LearnTestApplication : No active profile set, falling back to 1 default profile: "default" 2024-05-11T01:32:14.486+02:00 INFO 10492 --- [LearnTest] [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode. 2024-05-11T01:32:14.517+02:00 INFO 10492 --- [LearnTest] [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 26 ms. Found 2 JPA repository interfaces. 2024-05-11T01:32:14.803+02:00 INFO 10492 --- [LearnTest] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http) 2024-05-11T01:32:14.811+02:00 INFO 10492 --- [LearnTest] [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2024-05-11T01:32:14.811+02:00 INFO 10492 --- [LearnTest] [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.19] 2024-05-11T01:32:14.851+02:00 INFO 10492 --- [LearnTest] [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2024-05-11T01:32:14.851+02:00 INFO 10492 --- [LearnTest] [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 705 ms 2024-05-11T01:32:14.874+02:00 INFO 10492 --- [LearnTest] [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2024-05-11T01:32:15.004+02:00 INFO 10492 --- [LearnTest] [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection conn0: url=jdbc:h2:mem:e7e97f48-70df-4ac1-8cb7-88dec0dd2f58 user=SA 2024-05-11T01:32:15.005+02:00 INFO 10492 --- [LearnTest] [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. 2024-05-11T01:32:15.012+02:00 INFO 10492 --- [LearnTest] [ main] o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:e7e97f48-70df-4ac1-8cb7-88dec0dd2f58' 2024-05-11T01:32:15.096+02:00 INFO 10492 --- [LearnTest] [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default] 2024-05-11T01:32:15.126+02:00 INFO 10492 --- [LearnTest] [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.4.4.Final 2024-05-11T01:32:15.145+02:00 INFO 10492 --- [LearnTest] [ main] o.h.c.internal.RegionFactoryInitiator : HHH000026: Second-level cache disabled 2024-05-11T01:32:15.284+02:00 INFO 10492 --- [LearnTest] [ main] o.s.o.j.p.SpringPersistenceUnitInfo : No LoadTimeWeaver setup: ignoring JPA class transformer 2024-05-11T01:32:15.897+02:00 INFO 10492 --- [LearnTest] [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration) Hibernate: drop table if exists employee cascade Hibernate: drop table if exists shift cascade Hibernate: create table employee (date_of_birthday date, rate float(53), type_of_contract tinyint check (type_of_contract between 0 and 3), id bigint generated by default as identity, first_name varchar(255), last_name varchar(255), pesel varchar(255), specialization varchar(255), zusindex varchar(255), primary key (id)) Hibernate: create table shift (date date, employee_id bigint, id bigint generated by default as identity, actual_end_time varchar(255), actual_start_time varchar(255), end_time varchar(255), start_time varchar(255), station varchar(255), primary key (id)) Hibernate: alter table if exists shift add constraint FKg9ycreft1sv2jjvkno3dn3fqy foreign key (employee_id) references employee 2024-05-11T01:32:15.928+02:00 INFO 10492 --- [LearnTest] [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default' 2024-05-11T01:32:16.066+02:00 INFO 10492 --- [LearnTest] [ main] o.s.d.j.r.query.QueryEnhancerFactory : Hibernate is in classpath; If applicable, HQL parser will be used. 2024-05-11T01:32:16.470+02:00 WARN 10492 --- [LearnTest] [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning 2024-05-11T01:32:16.677+02:00 WARN 10492 --- [LearnTest] [ main] .b.a.g.t.GroovyTemplateAutoConfiguration : Cannot find template location: classpath:/templates/ (please add some templates, check your Groovy configuration, or set spring.groovy.template.check-template-location=false) 2024-05-11T01:32:16.836+02:00 INFO 10492 --- [LearnTest] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '' 2024-05-11T01:32:16.841+02:00 INFO 10492 --- [LearnTest] [ main] i.d.learntest.LearnTestApplication : Started LearnTestApplication in 3.117 seconds (process running for 3.473) Hibernate: insert into employee (pesel,zusindex,date_of_birthday,first_name,last_name,rate,specialization,type_of_contract,id) values (?,?,?,?,?,?,?,?,default) Hibernate: insert into shift (actual_end_time,actual_start_time,date,employee_id,end_time,start_time,station,id) values (?,?,?,?,?,?,?,default) Hibernate: insert into shift (actual_end_time,actual_start_time,date,employee_id,end_time,start_time,station,id) values (?,?,?,?,?,?,?,default) Hibernate: insert into shift (actual_end_time,actual_start_time,date,employee_id,end_time,start_time,station,id) values (?,?,?,?,?,?,?,default) Hibernate: insert into shift (actual_end_time,actual_start_time,date,employee_id,end_time,start_time,station,id) values (?,?,?,?,?,?,?,default)
after save all
Hibernate: select e1_0.id,e1_0.pesel,e1_0.zusindex,e1_0.date_of_birthday,e1_0.first_name,e1_0.last_name,e1_0.rate,e1_0.specialization,e1_0.type_of_contract from employee e1_0 Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=? Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=?
All employees [Employee{id=1, firstName='Adam', lastName='Kowalski', rate=23.5, typeOfContract=null, specialization='null', dateOfBirthday=null, PESEL='03947283728', ZUSindex='null'}] Hibernate: select e1_0.id,e1_0.pesel,e1_0.zusindex,e1_0.date_of_birthday,e1_0.first_name,e1_0.last_name,e1_0.rate,e1_0.specialization,e1_0.type_of_contract,ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from employee e1_0 left join shift ws1_0 on e1_0.id=ws1_0.employee_id where e1_0.id=? Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=?
salary= 0.0 Hibernate: select e1_0.id,e1_0.pesel,e1_0.zusindex,e1_0.date_of_birthday,e1_0.first_name,e1_0.last_name,e1_0.rate,e1_0.specialization,e1_0.type_of_contract,ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from employee e1_0 left join shift ws1_0 on e1_0.id=ws1_0.employee_id where e1_0.id=? Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=?
tax= {social security contributions=0.0, advance income tax=-30.0, Health insurance contribution=0.0, PPK=0.0, Tax=-330.0} Hibernate: select e1_0.id,e1_0.pesel,e1_0.zusindex,e1_0.date_of_birthday,e1_0.first_name,e1_0.last_name,e1_0.rate,e1_0.specialization,e1_0.type_of_contract,ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from employee e1_0 left join shift ws1_0 on e1_0.id=ws1_0.employee_id where e1_0.id=? Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=?
Revenue= 0.0 Hibernate: select e1_0.id,e1_0.pesel,e1_0.zusindex,e1_0.date_of_birthday,e1_0.first_name,e1_0.last_name,e1_0.rate,e1_0.specialization,e1_0.type_of_contract from employee e1_0 Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=? Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=?
Employee{id=1, firstName='Adam', lastName='Kowalski', rate=23.5, typeOfContract=null, specialization='null', dateOfBirthday=null, PESEL='03947283728', ZUSindex='null'} have [] Hibernate: select s1_0.id,s1_0.actual_end_time,s1_0.actual_start_time,s1_0.date,s1_0.employee_id,s1_0.end_time,s1_0.start_time,s1_0.station from shift s1_0 Hibernate: select e1_0.id,e1_0.pesel,e1_0.zusindex,e1_0.date_of_birthday,e1_0.first_name,e1_0.last_name,e1_0.rate,e1_0.specialization,e1_0.type_of_contract,ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from employee e1_0 left join shift ws1_0 on e1_0.id=ws1_0.employee_id where e1_0.id=? Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=?
Hibernate: select count(*) from employee e1_0 where e1_0.id=? Hibernate: select s1_0.id,s1_0.actual_end_time,s1_0.actual_start_time,s1_0.date,s1_0.employee_id,s1_0.end_time,s1_0.start_time,s1_0.station from shift s1_0 where s1_0.employee_id=? Hibernate: select e1_0.id,e1_0.pesel,e1_0.zusindex,e1_0.date_of_birthday,e1_0.first_name,e1_0.last_name,e1_0.rate,e1_0.specialization,e1_0.type_of_contract,ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from employee e1_0 left join shift ws1_0 on e1_0.id=ws1_0.employee_id where e1_0.id=? Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=?
Hibernate: select e1_0.id,e1_0.pesel,e1_0.zusindex,e1_0.date_of_birthday,e1_0.first_name,e1_0.last_name,e1_0.rate,e1_0.specialization,e1_0.type_of_contract from employee e1_0 where e1_0.pesel=? Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=? Hibernate: select ws1_0.employee_id,ws1_0.id,ws1_0.actual_end_time,ws1_0.actual_start_time,ws1_0.date,ws1_0.end_time,ws1_0.start_time,ws1_0.station from shift ws1_0 where ws1_0.employee_id=?
employee with peselEmployee{id=1, firstName='Adam', lastName='Kowalski', rate=23.5, typeOfContract=null, specialization='null', dateOfBirthday=null, PESEL='03947283728', ZUSindex='null'} [/code] Я использую базу данных h2 Пытался изменить порядок добавления объектов в базу, проверил два кода (рабочий и неработающий), извлекал объекты разными способами, удалял и добавлял аннотации к классам сущностей Ожидаю, что при получении сотрудника из базы поле "Рабочие смены" заполнится соответствующими значениями
У меня есть что-то вроде этого:
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, declarative_base
from sqlalchemy import Column, Integer, String, ForeignKey
Пытаюсь сделать простую программу для построения графика работы, но не могу правильно получить данные. когда я пытаюсь нанять сотрудника
@Entity
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Employee {