我有一个实体Period
@Entity
@Table(name = "period")
public class Period implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Enumerated(EnumType.STRING)
@Column(name = "day_of_week")
private DayOfWeek dayOfWeek;
@Column(name = "start_time")
private LocalTime startTime;
@Column(name = "end_time")
private LocalTime endTime;
@JsonIgnoreProperties(value = { "period" }, allowSetters = true)
@OneToOne
@JoinColumn(unique = true)
private Periodicity periodicity;与之相关的实体Periodicity
@Entity
@Table(name = "periodicity")
public class Periodicity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Enumerated(EnumType.STRING)
@Column(name = "periodicity_label")
private TypeOfPeriodicity periodicityLabel;
@Column(name = "end_time")
private LocalTime endTime;
@JsonIgnoreProperties(value = { "periodicity", "resource" }, allowSetters = true)
@OneToOne(mappedBy = "periodicity")
private Period period;同时也是一个枚举TypeOfPeriodicity
public enum TypeOfPeriodicity {
JOURNALIER,
HEBDOMADAIRE,
MENSUEL,
SEMESTRIEL,
TRIMESTRIEL,
ANNUEL,
}在创建新句点时,在字体结束时,我指定该句点的TypeOfPeriodicity。在后端,我想从句点取TypeOfPeriodicity和endTime,同时使用这些属性保存一个新的周期性。知道怎么做吗?我需要帮助。
发布于 2022-07-18 12:24:22
在周期类中,可以使用@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)使hibernate在保存周期实体时保持周期性实体。有关https://www.baeldung.com/jpa-cascade-types类型的更多信息,请参见CascadeType,通常使用的都是
https://stackoverflow.com/questions/73022108
复制相似问题