hibernate 不会在父对象中加载子对象

问题描述 投票:0回答:1

我正在尝试编写一个简单的程序来构建工作计划,但无法正确获取数据。当我试图招募员工时

@Entity
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Employee {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String firstName;
    private String lastName;
    private Double rate;
    private TypeOfContract typeOfContract;
    private String specialization;
    private LocalDate dateOfBirthday;
    private String PESEL;
    private String ZUSindex;

    @OneToMany(mappedBy = "employee", fetch = FetchType.EAGER)
    Set<Shift> workedShift= new HashSet<>();

    public String getFullName() {
        return firstName+" "+lastName;
    }
    public void setFullName(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }
    @Override
    public String toString() {
        return "Employee{" +
                "id=" + id +
                ", firstName='" + firstName + '\'' +
                ", lastName='" + lastName + '\'' +
                ", rate=" + rate +
                ", typeOfContract=" + typeOfContract +
                ", specialization='" + specialization + '\'' +
                ", dateOfBirthday=" + dateOfBirthday +
                ", PESEL='" + PESEL + '\'' +
                ", ZUSindex='" + ZUSindex + '\'' +"}";
    }
}

从数据库中,当我尝试获取班级班次时,现场工作班次为空

@Entity
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Shift implements Comparable<Shift>{

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String station;
    private LocalDate date;
    private String startTime;
    private String endTime;
    private String actualStartTime;
    private String actualEndTime;
    @ManyToOne
    Employee employee;

    public HoursClass getWorkedTime() {
        if (this.actualStartTime == null || this.actualEndTime == null) {
            return null; 
        }

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
        LocalTime localStartTime = LocalTime.parse(this.actualStartTime, formatter);
        LocalTime localEndTime = LocalTime.parse(this.actualEndTime, formatter);
        Duration duration;

        if (localEndTime.isBefore(localStartTime)) {
            duration = Duration.between(localStartTime, LocalTime.MAX).plus(Duration.between(LocalTime.MIN, localEndTime));
        } else {
            duration = Duration.between(localStartTime, localEndTime);
        }

        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 +
                '}';
    }
}

从数据库中,employee 字段正确填充了数据,我尝试使用 findAll() 方法(为我们提供 JPA 接口)和使用自定义方法从数据库获取数据

public interface EmployeeRepository extends JpaRepository<Employee,Long> {

    ///**
    //* 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<Employee> 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<Shift> 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"));
    }
}

这里我将数据保存到数据库,然后实际检索它,当我通过控制器操作数据时,我也观察到了问题。 这就是数据库填充数据后的样子

[shift table](https://i.sstatic.net/26KW7O4M.png) 
[employee table](https://i.sstatic.net/mhdSRqDs.png)

,这是运行类后控制台直接显示的日志


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: 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数据库

我尝试更改向数据库添加对象的顺序,我检查了两个代码(工作和不工作),以不同的方式检索对象,删除并添加了实体类的注释

我希望当从数据库接收员工时,工作班次字段将填充适当的值

java spring hibernate jpa h2
1个回答
0
投票

都是关于注解@Data的,当我删除它时,问题就消失了

© www.soinside.com 2019 - 2024. All rights reserved.