gpt4 book ai didi

java - Hibernate映射内部类,错误 "Could not determine type for: timeStamps"

转载 作者:行者123 更新时间:2023-12-02 01:44:00 25 4
gpt4 key购买 nike

我有一个实体“任务”,它需要一个名为“时间戳”的内部组件,该组件保存任务提交、启动和完成时的值。

@Entity
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer Id;
private String Status;
private Timestamps timestamps;
// getters setters
}

然后我创建了 Timestamps 类

public class Timestamps {
private Timestamp submitted;
private Timestamp started;
private Timestamp completed;
//getter and setters
}

如何进行此映射,以便当我检索 JSON 格式的信息时得到类似的内容?

# task
{
"task": # ASCII string
"status": # one of "submitted", "started", "completed"
"timestamps": {
"submitted": # unix/epoch time
"started": # unix/epoch time or null if not started
"completed": # unix/epoch time or null if not completed
}
}

最佳答案

您可以将 @Embeddable 注释放在时间戳上。 Hibernate 会将字段映射为同一个表中的列。您可能还需要在任务中的时间戳字段上使用@Embedded(我无法确定双方是否都需要注释)。

关于java - Hibernate映射内部类,错误 "Could not determine type for: timeStamps",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53970048/

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