简体   繁体   中英

saving custom object Type variable using hibernate

i have a spring boot and hibernate based project that contains a simple schedule(pojo) class and an entity class to save in mysql using hibernate.

Now i want to create a field in tutorAvailableSchedules entity which is an array of schedule type. when i try the below code it gives me the error.

availableSchedule.class ->pojo

package fG.Model;

import java.util.Arrays;

public class availablitySchedule {
    String startTime;
    String endTime;
    String days[];
}

TutorAvailablitySchedules.class ->Entity

package fG.Entity;
import fG.Model.availablitySchedule;

@Entity
public class TutorAvailablitySchedules {

    @Id
    Integer tid;
    String fullName;
    availablitySchedule[] availableSchedules;
    String currentSchedule;
    String availablityStatus;
}

error i get:

 Could not determine type for: fG.Model.availablitySchedule, at table: tutor_availablity_schedules, for columns: [org.hibernate.mapping.Column(available_schedules)]

I will sketch you a possible solution. It may need some refinement, depending on how you want to model the relationship of your entities.

  1. You could annotate class AvailablitySchedule as @Entity such that it reflects a table. As a consequence you will have to think about an id.
  2. Refactor AvailablitySchedule[] availableSchedules in class TutorAvailablitySchedules to List<AvailablitySchedule> availableSchedules
  3. Define a @OneToMany relationship between TutorAvailablitySchedules and AvailablitySchedule by annotating field List<AvailablitySchedule> availableSchedules in TutorAvailablitySchedules with @OneToMany
  4. Change String[] days; to List<String> days; in class AvailablitySchedule
  5. Annotate List<String> days; with eg @ElementCollection .
  6. Look at the tables that are created and think about if this is the structure you want to have.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM