gpt4 book ai didi

java - OneToMany spring 表单问题

转载 作者:太空宇宙 更新时间:2023-11-04 13:49:57 26 4
gpt4 key购买 nike

在尝试为 OneToMany 映射创建 Spring 表单时,我收到以下错误

org.springframework.beans.NotReadablePropertyException: Invalid property 'reminder[0].id' of bean class [com.medicine.yourmedics.model.Medication_$$_jvst99a_7]: Field 'reminder[0].id' does not exist

我的 Pojo 药物类(class)是

@Entity
@Table(name = "MEDICATION")
@JsonAutoDetect
public class Medication {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id", unique = true, nullable = false)

@OneToMany(mappedBy = "medication")
private List<Reminder> reminder = new ArrayList<Reminder>();

提醒 Pojo 看起来像

public class Reminder {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id", unique = true, nullable = false)
private int id;

@ManyToOne
@JoinColumn(name = "medication_id")
private Medication medication;

我已经创建了一个药物表格,我试图在其中访问提醒 ID

<c:forEach items="${medication.reminder}" varStatus="loop">
<form:input path="reminder[${loop.index}].id" />
</c:forEach>

请大家帮帮我。我很难找出其中的问题。

最佳答案

根据 Java Doc对于@OneToMany...

(Optional) Whether the association should be lazily loaded or must be eagerly fetched. The EAGER strategy is a requirement on the persistence provider runtime that the associated entities must be eagerly fetched. The LAZY strategy is a hint to the persistence provider runtime.

Default: javax.persistence.FetchType.LAZY

尝试@OneToMany(mappedBy = "medication", fetch = FetchType.EAGER)要求hibernate急切地加载列表中的数据而不是提供代理

关于java - OneToMany spring 表单问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30412079/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com